asp.net mvc - How to Pass Kendo DropDownList DataTextField value to Controller -
i have kendo dropdownlist
on view
, want pass datatextfield
value controller
, pass , them on labels in view
. although can pass datavaluefield
values controller
, cannot pass datatextfield
values. tried apply different scenarios not. idea? on other hand, if not possible, should datatextfield
values populated again on controller
, return 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); } /* want pass datatextfield values method , return them createmanagement view */ public actionresult create(issueviewmodel issueviewmodel) { return redirecttoaction("createmanagement", issueviewmodel); }
change controller 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 dropdownlist
uses datatextfield
user , uses datavaluefield
server communications, have use datatextfield
value both. then can use next operations.
edit: if need both values on controller, change jsonresult
method :
return json(projects.select(m => new selectlistitem { projectid = m.description + "," + m.id , projectname = m.description }).tolist(), jsonrequestbehavior.allowget);
now can use both in next operations spiting them like:
var _both = value.split(',');//value: returned value view
Comments
Post a Comment