Reading the value of the kendoui dropdownlist

If you set the Name value of your DropDownList to match the ViewModel’s property name then it will bind directly to the ViewModel and you can just read the viewModel’s property.

In my sample the ViewModel contains an object and I want to bind to that, therefore I have  Name with a ‘.’ in it ( “Goal.GroupId”).

 

@(Html.Kendo().DropDownList()
.Name(“Goal.GroupId”)
.HtmlAttributes(new {style = “width:250px”})
.DataTextField(“Product_Group_Description”)
.DataValueField(“Product_Group_Code”)
.DataSource(source =>
{
source.Read(read =>
{
read.Action(“GetJsonGroupList”, “Goal”);
});
})
)

In the Post action that is called when the form is submitted, I can the value in 2 ways:

public ActionResult Index(FormCollection collection, Manage_GoalIndexVm vm)
{
string groupId = vm.Goal.GroupId;  // this is my preferred way
string g2 = collection[“Goal.GroupId”].ToString();  //but this is an option

return RedirectToAction(“Index”);
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s