如何通过剑道DropDownList的DataTextField值控制器 [英] How to Pass Kendo DropDownList DataTextField value to Controller
问题描述
我有一个剑道的DropDownList
在查看
,我想通过它的 DataTextField
值到控制器
,然后将它们在标签上的另一个查看通和code>。虽然我可以通过
并返回到在另一方面,如果它是不可能的,应在 DataValueField
值到控制器
,我无法通过 DataTextField
值。我尝试应用不同的情况,但我不能。任何想法? DataTextField
值再次在控制器填充其他
查看
?
查看:
@model IssueViewModel...
@ Html.LabelFor(M = GT; m.ProjectID)
@(Html.Kendo()。DropDownList的()
。名称(专案编号)
.DataTextField(项目名)
.DataValueField(专案编号)
.DataSource(来源= GT;
{
source.Read(读=>
{
read.Action(GetProjects,发行);
});
})
)
控制器:
公共JsonResult GetProjects()
{
VAR项目= repository.Projects;
返回JSON(projects.Select(M = gt;新建{专案编号= m.ID,项目名= m.Description}),JsonRequestBehavior.AllowGet);
}
/ *我想通过DataTextField值这个
方法,并将其退回到CreateManagement视图* /
公众的ActionResult创建(IssueViewModel issueViewModel)
{
返回RedirectToAction(CreateManagement,issueViewModel);
}
控制器改成这样:
公共JsonResult GetProjects()
{
VAR项目= repository.Projects;
返回JSON(projects.Select(M = gt;新建SelectListItem {专案编号= m.Description,项目名= m.Description})了ToList(),JsonRequestBehavior.AllowGet。);
}
由于的DropDownList
使用 DataTextField
为用户和用途 DataValueField
服务器通讯,所以你必须使用 DataTextField
值两者。的然后你可以使用它在未来的操作。的
修改:如果您在控制器上需要这两个值,变 JsonResult
方法:
返回JSON(projects.Select(M = gt;新建SelectListItem {专案编号= m.Description +,+ m.ID,项目名= m.Description})了ToList(。 ),JsonRequestBehavior.AllowGet);
现在你就能通过吐涎他们如同时使用,在未来的操作:
VAR _both = value.split(''); //值:从视图返回的值
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:
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 :
return Json(projects.Select(m => new SelectListItem { 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
这篇关于如何通过剑道DropDownList的DataTextField值控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!