I am dynamically generating a dropdownbox.
I am trying to send the selected value in dropdown box as one of the fields of a model to controller.
@using (Html.BeginForm("AddItem", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<label>
Category:</label>
@Html.DropDownList("Category", (IEnumerable<SelectListItem>)ViewData["CategoryList"])<br />
<label>
Sku:</label>
@Html.TextBox("newItem.Sku")<br />
<label>
Title:</label>
@Html.TextBox("newItem.Title")<br />
I am able to send all the values as a part of model, except the value of Category(dropdownbox value), hence making the function in controller to fail..
ANSWER: Renaming the Dropdownlist “Category” to = “newItem.Category”, did the work, basically it should match the model name.
Renaming the Dropdownlist “Category” to = “newItem.Category”, did the work, basically if you expect a model to be received in controller, which in this case was “newItem”, down control name should match the model name and its property.