I am attempting to pass my model on change of a DropDownList in my Razor code but my model information is not getting passed to the post method, even thouugh the post method is being called.
In my Razor:
@model Namespace.Models.MyModel
@using (Html.BeginForm("myFunc", "Home", FormMethod.Post, new { myModel = Model }))
{
@Html.DropDownListFor(m => m.SelectedType, new SelectList(Model.Types, "Id", "Desc", Model.SelectedType), new { @class = "form-control", style = "display: inline;", @onchange = "this.form.submit()" })
}
My model:
public class MyModel
{
public List<myData> myList = new List<myData>();
public List<myType> Types = new List<myType>();
public string SelectedType;
}
My controller:
[HttpPost]
public ActionResult myFunc(MyModel myModel)
{
//do stuff
}
If I place a breakpoint in myFunc I can see it stepping into there on change of my DropDownList but the model information does not pass to the function. I'm sure what I am missing is probably a minor thing but I just cannot see it.
The rendered HTML is:
<form action="/Home/myFunc" myModel="Namespace.Models.MyModel" method="post">
<select class="form-control" id="SelectedType" name="SelectedType" onChange="(this.form).submit()" style="display: inline;">
<option selected="selected" value="FT">Fault</option>
<option value="QY">Query</option>
<option value="RQ">PM Request</option>
</select>
</form>
@model MyModelline under your@usingstatements?SelectedTypeproperty is empty or the lists of values are empty?