我有以下模型类:-
public partial class SecurityroleTypePermision
{
public int SecurityRoleID { get; set; }
public int PermisionLevelID { get; set; }
public int AssetTypeID { get; set; }
public virtual PermisionLevel PermisionLevel { get; set; }
public virtual SecurityRole SecurityRole { get; set; }
public virtual TechnologyType TechnologyType { get; set; }
}
以及以下视图:-
@using (Html.BeginForm("AssignPermisionLevel2", "SecurityRole"))
{@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<tr>
<th></th><th></th></tr>
@{int i = 0;
foreach (var item in Model.TechnologyType.OrderBy(a=>a.Name)) {
string s = "Model." + item.Name.ToLower() + "PermisionLevel" ;
<tr><td class="f">
@item.Name : @Html.DropDownList("@[i]+PermisionLevelID", new SelectList(Model.PermisionLevel, "PermisionLevelID", "Name",s))
@Html.Hidden("@[i]+ AssetTypeID",item.AssetTypeID)
@Html.Hidden("@[i]SecurityRoleID",Model.SecurityRole.SecurityRoleID)
@(i = i+1);
</td><td class="f"></td></tr>}
}
</tbody></table>
<input type="submit" value="Assign" class="btn btn-primary"/>
</div></div></div>}
以及以下动作方法:-
[HttpPost]
public ActionResult AssignPermisionLevel2(ICollection<SecurityroleTypePermision> list)
{foreach (var c in list)
{repository.InsertOrUpdateSecurityroleTypePermisions(c); }
repository.Save();
return RedirectToAction("Index");}
但是我如何将包含下拉选择和两个隐藏字段的值列表提交给我的操作方法?//提示我只是在视图中添加了 [i] 仅用于测试目的。