我的观看代码是:
@using(Html.BeginForm("submit","Security",FormMethod.Post))
{
@foreach (var item in Model.app_function)
{
<input type="checkbox" name="Functioncheck" value="@item.app_function_id"/>
@Html.Encode(item.app_function_name)
}
<input type="submit" value="submit" />
}
单击提交按钮后,选中的值将保存到数据库中,但未选中已检查的值。
我的控制器代码是:
[AcceptVerbs(HttpVerbs.Post)]
public ViewResult submit(FormCollection fm)
{
string Roleecheck = Request.Form["Functioncheck"].ToString();
string[] x = Roleecheck.Split(',');
int a = Convert.ToInt32(x.Length);
for (int i = 0; i < x.Length; i++)
{
int userid = Convert.ToInt32(x[i]);
var myEntity = new user_role { role_id = id, user_id = userid, created_date = DateTime.Now, created_by = 1 };
UpdateModel(myEntity);
am.Add(myEntity);
}
am.Save();
return view();
}
点击提交后,让我知道如何设置复选框选中的项目。
感谢。