1

私のMVC(Razor)プロジェクトでは、疑問があります。Hierarchy.cshtml という名前の Razor ビューがあります。

意見:

@model List<DatabaseModel.SampleWizardModel>
<script>
    $(document).ready(function () {
        $('.chk-act').click(function () {
            if ($(this).is(':checked')) {
                $('#AttributeList' + this.value).data("tDropDownList").enable();
            }
            else {
                $('#AttributeList' + this.value).data("tDropDownList").disable();
            }
        });
    });

    function SetAllCheckBoxes(obj) {
        var c = new Array();
        c = document.getElementsByTagName('input');
        for (var i = 0; i < c.length; i++) {
            if (c[i].type == 'checkbox') {
                c[i].checked = obj.checked;
            }
        }
        $('.chk-act').each(function () {
            if ($(this).is(':checked')) {
                $('#AttributeList' + this.value).data("tDropDownList").enable();
            }
            else {
                $('#AttributeList' + this.value).data("tDropDownList").disable();
            }
        });
    }

    function onAttListChange(e) {
        $('#hdattid').val($("#" + this.id).data("tDropDownList").text());
       // $get("tDropDownList").value = e.get_item().get_value();
    }

</script>

<div>
    <table border="0">
        <tr>
            <th align="center">Colum Name</th>
            <th align="center" width="150px">Import</br>(<input type="checkbox" name="chkselectall" onclick="SetAllCheckBoxes(this)" /><i>Select All </i>)</th>
            <th align="center">Field Mapping</th>
        </tr>
        @using (Html.BeginForm("SampleImport", "Sample", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
            foreach (var item in Model)
            {
                string checkbox = "actionChk" + item.Index;
            <tr>
                <td>@item.ColumName</td>
                <td align="center">
                    <input type="checkbox" class="chk-act" id="@checkbox" value="@item.Index" name="@checkbox"></td>
                <td>
                    <div id="dd">@(Html.Telerik().DropDownListFor(m => m.FirstOrDefault().DropDownAttributes).Name("AttributeList" + item.Index).BindTo(item.DropDownAttributes).ClientEvents(e =>e.OnChange("onAttListChange")).HtmlAttributes(new { style = "width:235px" }).Enable(false))</div>
                    @Html.Hidden("hdattid" + item.Index, item.DropDownAttributes.FirstOrDefault().Text)
                </td>
            </tr>
            }
            <tr>
                <td></td>
                <td></td>
                <td><b><i>@Html.CheckBox("Allow Duplicate", false) Allow Duplicate</i></b>
                    <input type="submit" value="Start Import" /></td>
            </tr>
        }

    </table>

</div>

私のモデルは次のとおりです。

#region SampleWizard Model Class
    public class SampleWizardModel
    {
        public int Index { get; set; }

        public string ColumName { get; set; }

        public bool Selected { get; set; }

        public int AttributrId { get; set; }

        public List<SelectListItem> DropDownAttributes { get; set; }

        public int AttributeTypeId { get; set; }

        public string AttributeName { get; set; }

    }
    #endregion

コントローラ:

[HttpPost]
    public ActionResult FinalImport(FormCollection collection)
    {
    List<DatabaseModel.HierarchyWizardModel> model = (List<DatabaseModel.HierarchyWizardModel>)Session["HierarchyWizardModel"];

    foreach (var key in collection.AllKeys)
    {
        if (key.Contains("actionChk"))
        {
            int Index = int.Parse(Request[key].ToString());
            var Item = model.Where(h => h.Index == Index).FirstOrDefault();
            Item.Selected = true;
            string Value = Request["AttributeList" + Index].ToString();
            if (Value == "Category" || Value == "SubCategory" || Value == "CatalogItemNo")
            {
                Item.AttributeName = Request["hdattid" + Index].ToString();
                Item.AttributrId = 0;
                Item.AttributeTypeId = 0;
            }
            else
            {
                Item.AttributeName = Request["hdattid" + Index].ToString();
                if (Request["hdattid" + Index].ToString().Contains("New Attribute"))
                {
                    Item.AttributeTypeId = int.Parse(Value);
                    Item.AttributrId = 0;
                }
                else
                {
                    Item.AttributrId = int.Parse(Value);
                    Item.AttributeTypeId = 0;
                }
            }
        }
    }
    return View();
}

ここで、実行すると実行されることを意味し、チェックボックスをオンにすると、ドロップダウンリストが有効になります。そして、そこから値を選択すると、他の値は返されず、最初の値のみが返されます。したがって、他の値を選択するときに他の値を取得する必要があります。HiddenField の Telerik のドロップダウンリストで選択されたテキストを取得する方法??? どんな助けでも

4

0 に答える 0