0
我有一個由dropdownlist元素組成的表單。我想要在控制器中獲取dropdownlist的值。 我不知道該怎麼做。我在控制器中使用dataview讀取用戶名,並希望通過dropdownlist選項更改它們的角色。我無法獲得mvc3中的下拉列表值
@using (Html.BeginForm()) {
<form name="register" action="#">
<div>
<table>
@foreach (MembershipUser user in Model)
{
var userroles = Roles.GetRolesForUser(user.UserName);
<tr>
<td>
@user.UserName
</td>
@foreach (var role in userroles)
{
<td>
@role
</td>
}
<td>
@Html.DropDownList("roleName")
@Html.ValidationMessage("roleName")
</td>
<td>
</td>
</tr>
}
</table>
<input type="submit" class="register" value="Save" />
</div>
</form>
}
,這是我的控制器:
public ActionResult Index()
{
ViewData["roleName"] = new SelectList(Roles.GetAllRoles(), "roleName");
return View(Membership.GetAllUsers());
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index()
{
return RedirectToAction("Index", "Home");
}
我想這和寫值出現錯誤頁面上響應.WRITE(roleNameSelectValue) –