I have 1 Client side drop down in the view. Content for Dropdowns is loaded from Js file.
On submit I want the selected dropdown value to be assigned to Model property and send it to Controller.
Model
public class TestMe
{
public int Id { get; set; }
public string Name {get; set; }
}
Controller
[HttpPost]
public ActionResult Edit (TestMe viewModel)
{
....
}
View
<select name="Id">
<option value="0">High</option>
<option value="1">Medium</option>
<option value="2">Low</option>
</select>
MVC 4 , Razor , C#.Net Visual Studio 2012.
Thanks in advance.
Why don’t generate this Dropdown by Html Helpers ??
Anyway just make sure that your Client side drop down is in the form tag and make it’s name just as your Model property name and everything should work.
I suppose that you’ve something like this.
and your drop down represent the Id property and your controller action is:
Then your drop down should has name attribute with “Id” value.