asp.net mvc - why kendo mvc combobox send (0 - null) value when using strong type view and every kendo control? -


i'm trying use mvc kendo ui have problem when using typed view, when submit form kendo control send null or 0 value controller !! anothe html helper control send correct value . set code example of work combobox .

model:

    public class sys_branches     {         public int id { get; set; }         [required]         [foreignkey("companyid")]         public sys_companies sys_companies { get; set; }          public   int companyid { get; set; }         public string code { get; set; }         [required(errormessage = "name required")]         public string namea { get; set; }         [required(errormessage = "name required")]         public string namee { get; set; }       } 

view:

@model  mvc_erp.models.sys_branches  @{     viewbag.title = "branches"; }      <div class="col-xs-12 col-sm-2">             @html.label("company")         </div>          <div class="col-xs-12 col-sm-10" style="margin-bottom: 5px">          @(html.kendo().dropdownlistfor(model => model.notes).name("companyid")                    .datatextfield("namee")                           .datavaluefield("id")                            .datasource(source => source                               .read(read => read                               .action("fillcompanies", "branches")                               )                                )                      )             </div> 

controller"

       public actionresult index(int? id, string submitbutton, sys_branches maintbl)        {                  //new or edit according id pass if 0 new else edit                if( modelstate.isvalid)                {                 if (insert(maintbl)) return redirecttoaction("index", new { id = maintbl.id                 }                //model not valid                return view(maintbl);          }          public actionresult fillcompanies([datasourcerequest]datasourcerequest request)         {             session["membershipid"] = 1;             int membershipid =convert.toint32(session["membershipid"]);             var m =  db.companies.where(b => b.membershipid == membershipid && b.deleted != true);              //return json(m.select(p => new { companyid = p.id, namee = p.namee }), jsonrequestbehavior.allowget);             return json(  m.asqueryable(), jsonrequestbehavior.allowget);         } 

your dropdown binded "notes" property, , name "companyid". class "sys_branches" not contain "notes" property.

use following code :

@(html.kendo().dropdownlistfor(model => model.companyid).name("companyid")               .datatextfield("namee")                       .datavaluefield("id")                        .datasource(source => source                           .read(read => read                           .action("fillcompanies", "branches")                           )                            )                  )     

on submit, value set in "companyid" property of class.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -