I'm building a simple form with a dropdown and a submit button.
@using(Html.BeginForm("Index", "Account", FormMethod.Post))
{
@Html.DropDownList(
"Roles",
new SelectList(new List<string> { "User", "Manager", "Chuck Norris" }),
new { id = "role", name="role" })
<input type="submit" value="Update" />
}
And my controller looks like this:
[HttpPost]
public ActionResult Index(string role) <-- role is null when clicking submit
{
}
I was kinda hoping the value from the dropdown would automatically be injected as parameter of my controller method, but this is not the case. Am I missing something or is it simply not possible to do it like this?
<select>withname="Roles"but your parameter is namedrole(not plural). Change one or the other. (attempting to usename = "role"is ignored by the method - fortunately)