I am using KendoUI on MVC4.
I have a DropDownList bound to a model property that is a empty string:
@(Html.Kendo().DropDownListFor(model => model.AppUserStatus)
.Name("userStatusDropDownList")
.DataTextField("Text")
.HtmlAttributes(new {style = "width:100%;"})
.DataValueField("Value")
.BindTo(@ViewBag.StatusList))
model.AppUserStatus is a string that is empty by default.
After the user selects a new item , or leaves the selected item as the default item (index 0) and posts the form back, the model.AppUserStatus is empty still, even though all the other fields are correctly bound:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Update(EditUserViewModel model)
{
model.AppUserStatus ***** IS Null always, all other fields are good
return View("EditUser", model);
}
You don’t need to set Name(“userStatusDropDownList”) property for control.
Remove it and the name will be auto generated properly – i.e. #AppUserStatus.
This Name method also controls the name by the value that is posted to the server – the name attribute of the input element which is posted.