Reputation: 5905
I have a view which has no Model. On design time it has 2 drop down lists with values. Below is my view code:
if (string.Equals("Home", @ViewContext.RouteData.Values["Controller"].ToString()))
{
using (Html.BeginForm("Submit","Home",FormMethod.Post,new {@class="firstform"}))
{
<div class="field vert">
<select>
<option>Home</option>
<option>Health</option>
</select>
</div>
<div class="field vert">
<select>
<option>Education</option>
<option>Designation</option>
</select>
</div>
<input type="submit" class="btn" value="Get Now"/>
}
}
My action is as below:
[HttpPost]
public ActionResult Submit(FormCollection f)
{
return View();
}
In action I couldn't find form values, Can you please guide me what I should do or what I m missing to get values in Submit
action.
I m putting break point and checking form collection has nothing. Please help
Upvotes: 0
Views: 883
Reputation: 18873
The Default binding in MVC is with name attribute so just give your select tag name attribute as shown :
<div class="field vert">
<select name="a">
<option>Home</option>
<option>Health</option>
</select>
</div>
<div class="field vert">
<select name="b">
<option>Education</option>
<option>Designation</option>
</select>
</div>
and get selected dropdown value with the help of name attribute at post controller.
Upvotes: 1