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);
}
DataTextField
s rather thanDataValueField
s on the controller, so why you don't enumerateDataTextField
s likeDataValueField
s? – Patrick<select>
only post back one element, so do you want the selected ProjectsID
orDescription
property to be posted? – BechuanalandID
property (as your doing now). If you also needDescription
in the POST method, then you should call the database again. – Bechuanaland