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 DataValueField
values to the Controller
, I cannot pass DataTextField
values. I tried to apply different scenarios but I could not. Any idea? On the other hand, if it is not possible, should the DataTextField
values be populated again on the Controller
and return to the other View
?
View:
@model IssueViewModel
...
@Html.LabelFor(m => m.ProjectID)
@(Html.Kendo().DropDownList()
.Name("ProjectID")
.DataTextField("ProjectName")
.DataValueField("ProjectId")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetProjects", "Issue");
});
})
)
Controller:
public JsonResult GetProjects()
{
var projects = repository.Projects;
return Json(projects.Select(m => new { ProjectId = m.ID, ProjectName = m.Description }), JsonRequestBehavior.AllowGet);
}
/* I want to pass the DataTextField values to this
method and return them to the CreateManagement view */
public ActionResult Create(IssueViewModel issueViewModel)
{
return RedirectToAction("CreateManagement", issueViewModel);
}
Change your controller to this:
Since the
DropDownList
usesDataTextField
for the user and usesDataValueField
for the server communications, so you have to useDataTextField
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 :Now you can use both in the next operations just by spiting them like: