This is a migrated thread and some comments may be shown as answers.

Edit problems with 2013.1.319

4 Answers 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
AP
Top achievements
Rank 1
Iron
Iron
Veteran
AP asked on 22 Mar 2013, 08:31 AM
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



4 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 26 Mar 2013, 08:18 AM
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!
0
AP
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 26 Mar 2013, 08:44 AM
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!
0
Petur Subev
Telerik team
answered on 27 Mar 2013, 03:32 PM
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!
0
AP
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 27 Mar 2013, 03:35 PM
Thanks,  I might try the internal build, before I look at updating my big project.
Tags
Grid
Asked by
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Petur Subev
Telerik team
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Share this question
or