kendo ui - KendoUI Grid - ForeignKey column not working in PopUp edit mode -


i've searched on place (understatement) solution case no avail until now. first, i'll explain scenario:

  • i have openaccess model exposed wcf data service (odata v3);
  • i have kendo mvc application;
  • i have view grid, set popup editing, ajax bound;

before posting code, let me explain issue/difficulty. have entity these properties:

  • textoid
  • titulo;
  • corpo;
  • tipotextoid;
  • tipotexto;

there foreignkey column set tipotextoid property get's correctly populated either in in-line or pop-up mode. when comes changing data, works in-line mode. issue need work in popup, since "corpo" property bound kendoui editor.

when in popup, not show correct value on dropdown neither changes when select it.

honestly i'm feeling stupid. tried every sample, post, article find no avail , i'm clueless.

i hope can me on this. in advance all!

so, here's code. view:

    @model ienumerable<kendomvc.costsimulatorservice.texto>  @{     viewbag.title = "textos";     layout = "~/views/shared/_layout.cshtml"; }  <h2>textos</h2>  @(html.kendo().grid(model) // bind grid model property of view       .name("grid")       .columns(columns =>       {           columns.bound(p => p.titulo);   //create column bound "productid" property           //columns.bound(p => p.isprivado).clienttemplate("<input type='checkbox' #= isprivado ? checked='checked': '' # class='chkbx' />"); //create column bound "productname" property           columns.template(@<text></text>).clienttemplate("<input type='checkbox' #= isprivado ? checked='checked': '' # class='chkbx' />"); //create column bound "productname" property           //columns.bound(p => p.tipostexto);           columns.foreignkey(p => p.tipotextoid,                                   (system.collections.ienumerable)viewdata["tipostexto"],                                   "tipotextoid",                                   "designacao")                             .title("tipo de texto").width(150);           columns.command(command =>            {                command.edit();                command.destroy();            }).width(200);       })       .toolbar(commands => commands.create())       .editable(editable => editable.mode(grideditmode.popup).templatename("texto"))       .datasource(datasource => datasource             .ajax() //specify server type             .model(model =>             {                 model.id(texto => texto.textoid); // specify property unique identifier of model                 model.field(texto => texto.textoid).editable(false); // make productid property not editable             })             .create(create => create.action("createtexto", "backoffice"))             .read(read => read.action("readtextos", "backoffice"))             .update(update => update.action("updatetexto", "backoffice"))             .destroy(destroy => destroy.action("destroytexto", "backoffice")))      .pageable() // enable paging      .sortable() // enable sorting      .selectable()      .filterable()      .scrollable()          )  <script type="text/javascript">     $(document).ready(function() {                 $("form.k-edit-form").kendovalidator();     }); </script> 

next, template:

@using system.web.mvc.html;  @model kendomvc.costsimulatorservice.texto  introduza o conteúdo que deseja  @html.hiddenfor(model => model.textoid) <div id="divwrapper" style="width:99%; float:left;">     <div>         @html.labelfor(model => model.titulo)     </div>     <div>         @html.editorfor(model => model.titulo)         @html.validationmessagefor(model => model.titulo)     </div>      <div>         @html.labelfor(model => model.corpo)     </div>     <div>         @(html.kendo().editorfor(model => model.corpo))         @html.validationmessagefor(model => model.corpo)     </div>     <div>         @html.labelfor(model => model.tipotextoid)     </div>     <div>         @*@(html.kendo().dropdownlistfor(model => model.tipostexto))         @html.validationmessagefor(model => model.tipostexto)*@         @(html.kendo().dropdownlistfor(m => m.tipotextoid)             .name("tipostexto")             .datatextfield("designacao")             .datavaluefield("tipotextoid")             .bindto((system.collections.ienumerable)             viewdata["tipostexto"]))     </div> </div> 

the controller:

using system; using system.collections.generic; using system.io; using system.linq; using system.web; using system.web.mvc; using kendo.mvc.extensions; using kendo.mvc.ui; using kendomvc.costsimulatorservice;  namespace kendomvc.controllers {     public partial class backofficecontroller : controller     {         #region crud          #region readtextos          public actionresult readtextos([datasourcerequest]datasourcerequest request)         {             costsimulatormodel modelo = new costsimulatormodel(new uri(@"http://localhost:53212/costsimulatormodelservice.svc/"));              iqueryable<texto> textos = modelo.textos;             datasourceresult resultado = textos.todatasourceresult(request);             viewdata["textos"] = textos;             return json(resultado, jsonrequestbehavior.allowget);         }          #endregion          #region createtexto          public actionresult createtexto([datasourcerequest]datasourcerequest request, texto texto)         {             if (modelstate.isvalid)             {                 costsimulatormodel modelo = new costsimulatormodel(new uri(@"http://localhost:53212/costsimulatormodelservice.svc/"));                  // create new product entity , set properties posted productviewmodel                 texto entity = new texto                 {                     textoid = texto.textoid,                     titulo = texto.titulo,                     corpo = texto.corpo,                     isprivado = texto.isprivado,                     tipotextoid = texto.tipotextoid,                     tipostexto = texto.tipostexto                 };                 modelo.addtotextos(entity);                 // insert entity in database                 modelo.savechanges();                 // productid generated database                 texto.textoid = entity.textoid;             }             // return inserted product. grid needs generated productid. return validation errors.             return json(new[] { texto }.todatasourceresult(request, modelstate));         }          #endregion          #region updatetexto          public actionresult updatetexto([datasourcerequest]datasourcerequest request, texto texto)         {             if (modelstate.isvalid)             {                 costsimulatormodel modelo = new costsimulatormodel(new uri(@"http://localhost:53212/costsimulatormodelservice.svc/"));                  // create new product entity , set properties posted productviewmodel                 var entity = new texto                 {                     textoid = texto.textoid,                     titulo = texto.titulo,                     corpo = texto.corpo,                     isprivado = texto.isprivado,                     tipotextoid = texto.tipotextoid,                     tipostexto = texto.tipostexto                 };                 // attach entity                 modelo.attachto("textos", entity);                 modelo.updateobject(entity);                 // update entity in database                 modelo.savechanges();              }             // return updated product. return validation errors.             return json(new[] { texto }.todatasourceresult(request, modelstate));         }          #endregion          #region destroytexto          public actionresult destroytexto([datasourcerequest]datasourcerequest request, texto texto)         {             if (modelstate.isvalid)             {                 costsimulatormodel modelo = new costsimulatormodel(new uri(@"http://localhost:53212/costsimulatormodelservice.svc/"));                  // create new product entity , set properties posted productviewmodel                 var entity = new texto                 {                     textoid = texto.textoid                     //titulo = texto.titulo,                     //corpo = texto.corpo,                     //isprivado = texto.isprivado,                     //tipotextoid = texto.tipotextoid                 };                 // attach entity                 modelo.attachto("textos", entity);                 // delete entity                 modelo.deleteobject(entity);                  // delete entity in database                 modelo.savechanges();             }             // return removed product. return validation errors.             return json(new[] { texto }.todatasourceresult(request, modelstate));         }          #endregion          #endregion     } } 

i've got sorted out precious kendoui's premium forums.

so, stop happening, 1 should use default editor template foreignkeycolumn editor "tipotextoid", so:

model:

[uihint("gridforeignkey")] public int employeeid { get; set; } 

custom popup template:

@(html.editorfor(m => m.employeeid))      

instead of using @(html.kendo().dropdownlistfor(m => m.tipotextoid)

hope may others struggling same thing.

all best!


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -