Edit problems with 2013.1.319

5 posts, 1 answers
  1. AP
    AP avatar
    222 posts
    Member since:
    Apr 2010

    Posted 22 Mar 2013 Link to this post

    I created a new MVC project in visual Studio 2012, using the telerik KendoUI for MVC Web Application template (after installing the 2013.1.319 release)  I then set up some grids and sparkline charts.

    These have worked, but when I set up an editable grid, I've encountered issues
    • The buttons for edit / update / cancel have the text underlined, like hyperlinks - which hasn't happened in other kendo projects I've created.
    • Clicking the update button, the controller saves the change, but the web page doesn't close the edit, (both using inline and the pop-up editors).
    • If I make the primary key field read-only, the value is not posted back to the controller, even though it's specified as the ModelID.

    I have put the page and controller code in an older project (v2012.2.913) and the first two issues disappear.

    The grid definition is:-

    <div style="font-size:small;width:700px; margin-bottom:15px;">
    @(Html.Kendo().Grid<PMS2Monitor.Models.SystemSetting>()
    .Name("settingsGrid")
    .Columns(columns=>
        {columns.Bound(p=>p.SettingCode);
        columns.Bound(p => p.SettingDescription).Title("Description");
     
        columns.Bound(p => p.SettingValue).Title("Value");
        columns.Command(command => { command.Edit();  });
          
        })
         .Editable(editable=>editable
            .Mode(GridEditMode.InLine))
     
        .Pageable()
        .Filterable()
         
        .DataSource(dataSource=>dataSource
            .Ajax()
            .Model(m=>m.Id(p=>p.SettingCode))
            .PageSize(8)
            .Events(events => events.Error("error"))
            .Read(read=>read.Action("InterfaceSettings","Home"))
             .Update(update=>update.Action("UpdateSetting","Home"))
            )
             
       
           ) </div>

    The object meta data is defined as:-

    [MetadataType(typeof(SystemSettingMD))]
       public partial class SystemSetting
       {
           public class SystemSettingMD
           {
              [ReadOnly(true)]
               public object SettingCode { get; set; }
     
               [ReadOnly(true), StringLength(50)]
               public object SettingDescription { get; set; }
     
               [StringLength(500), Required]
               public object SettingValue { get; set; }
     
           }
       }

    The controller is:-

     

    public ActionResult InterfaceSettings([DataSourceRequest] DataSourceRequest request)
           {
     
               var query = _repository.GetSettings();
     
               query = query.OrderByDescending(c => c.SettingCode);
     
               return Json(query.ToDataSourceResult(request));
     
           }
     
           [AcceptVerbs(HttpVerbs.Post)]
           public ActionResult UpdateSetting([DataSourceRequest] DataSourceRequest request, Models.SystemSetting setting)
           {
               try
               {
                   _repository.updateSetting(setting);
     
                   return Json(ModelState.ToDataSourceResult());
               }
               catch (Exception ex)
               {
                   ModelState.AddModelError("ERR1", ex.Message);
     
                   return Json(ModelState.ToDataSourceResult());
               }
     
     
     
           }

    I've attached a screenshot of the grid buttons.

    Thanks



  2. Answer
    Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 26 Mar 2013 Link to this post

    Hello Andrew,


    Basically with the new version which uses the new version of jQuery empty string is no longer a valid JSON. So you have to change the update action of your controller to return the updated records.
    e.g.
    public ActionResult UpdatePerson([DataSourceRequest] DataSourceRequest dsRequest, Person person)
    {
        if (person != null && ModelState.IsValid)
        {
            var toUpdate = people.FirstOrDefault(p => p.PersonID == person.PersonID);
            TryUpdateModel(toUpdate);
        }
     
        return Json(new Person[] { toUpdate}.ToDataSourceResult(dsRequest, ModelState));
    }

    Regarding the first question with the underlined links - we are not sure what could be the reason for this - it might be CSS related. Check the attached project if there is something that I have missed update it and send it back so we can investigate further.

    When the ReadOnly data annotion attribute is set the value is submitted to the server you can check the network tab of your browser (or use tool like Fiddler), however the MVC model binder does not bind the incoming value to the property of your model.

    I would suggest you to set the editable option of that field to false instead.

    .Model(model => {
        model.Id(m => m.PersonID);
        model.Field(m=>m.PersonID).Editable(false);
    })


    Kind regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. AP
    AP avatar
    222 posts
    Member since:
    Apr 2010

    Posted 26 Mar 2013 Link to this post

    Thanks for this.

    It seems that this update behaviour is a fairly major breaking change, is this highlighted anywhere?  I can't see it in the release notes for 2013.1.319, and your Grid documentation, still shows an update controller which doesn't return anything:-

    I'm just glad this is a small project, if I had upgraded the big project I'm working on, it would have broken about 30 grids!
  4. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 27 Mar 2013 Link to this post

    Hello Andrew,

    It is covered in this sticky thread and it will be also added to the documentation. There is already internal build which will resolve this problem internally by the MVC Extensions.

    Kind Regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  5. AP
    AP avatar
    222 posts
    Member since:
    Apr 2010

    Posted 27 Mar 2013 Link to this post

    Thanks,  I might try the internal build, before I look at updating my big project.
Back to Top