I have a form using this model:
public class MyModel
{
public User SalesManager {get;set;}
public string Title {get;set;}
...
}
rendered like this using a DropDown given a list of Users in a HtmlHelper extension:
<label for="SalesManager">Sales Manager</label>
<select id="SalesManager" name="SalesManager">
<option value="7">James Morrison</option>
<option selected="selected" value="300">Ray Manzarek</option>
<option value="302">Robby Krieger</option>
<option value="302">John Densmore</option>
</select>
and an action like this:
[HttpPost]
public ActionResult SomeAction(FormCollection form)
{
...
}
I’m getting a validation ModelState error: The value '302' is invalid for the SalesManager property. How can I accept just an int value, and worry about instantiating my User later (in a ModelBinder for example). Or am I just approaching this wrong?
Your HTML should look like this:
because you cannot the value
302to a complex object such asUser.So the helper should look like this: