在我的 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 下拉列表中选择的文本???任何帮助