How To Pass Kendo Dropdownlist Datatextfield Value To Controller
I have a Kendo DropDownList on the View and I want to pass its DataTextField value to the Controller and then pass and them on the labels in another View. Although I can pass DataV
Solution 1:
Change your controller to this:
public JsonResult GetProjects()
{
var projects = repository.Projects;
return Json(projects.Select(m => new SelectListItem { ProjectId = m.Description, ProjectName = m.Description }).ToList(), JsonRequestBehavior.AllowGet);
}
Since the DropDownList
uses DataTextField
for the user and uses DataValueField
for the server communications, so you have to use DataTextField
value for both. Then you can use it for the next operations.
Edit: if you need both values on the controller, change JsonResult
method to :
returnJson(projects.Select(m =>newSelectListItem { ProjectId = m.Description + "," + m.ID , ProjectName = m.Description }).ToList(), JsonRequestBehavior.AllowGet);
Now you can use both in the next operations just by spiting them like:
var _both = value.split(',');//value: returned value from the view
Post a Comment for "How To Pass Kendo Dropdownlist Datatextfield Value To Controller"