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

Strange Behavior with MVC Wrapper Grid and null value being passed for field

2 Answers 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 24 Nov 2012, 05:46 AM
For some strange reason, the GroupName column returns a null value to the controller even though I enter a value into the grid UI. The GroupDescription column passes the entered value successfully. Both columns are strings except GroupName is a required field in the GroupVM view model. The work around is that I have to use a clientemplate for GroupName (see below)

THIS WORKS: columns.Bound(p => p.GroupName).ClientTemplate("#=GroupName #").Title("Group Name");
THIS DOES NOT WORK: columns.Bound(p => p.GroupName).Title("Group Name");



@model IEnumerable<
ViewModels.GroupVM>
 
@(Html.Kendo().Grid<ViewModels.GroupVM>()
 
.Name("GroupGrid")
    .ToolBar(toolbar => toolbar.Create().Text("Create"))
                .Editable(editable => editable.Mode(GridEditMode.InLine))
                .Pageable()
                .Sortable()
                .Scrollable()
.Columns(columns =>
     {
         columns.Bound(p => p.GroupId).Hidden();
         columns.Bound(p => p.GroupName).ClientTemplate("#=GroupName #").Title("Group Name");
         columns.Bound(p => p.GroupDescription).Title("Group Description");
         columns.Command(command => { command.Edit(); }).Width(200);
     })
          .DataSource(dataSource => dataSource
                    .Ajax()
                    .Model(model =>
                            {
                                model.Id(p => p.GroupId);
                            })                    
                        .Events(events => events.Error("error_handler"))
                        .Create(update => update.Action("ManageGroups_C", "Group"))
                        .Read(read => read.Action("ManageGroups_R", "Group"))
                        .Update(update => update.Action("ManageGroups_E", "Group"))
                )
     )
 
      <script type="text/javascript">
         function error_handler(e) {
             if (e.errors) {
                 var message = "Errors:\n";
                 $.each(e.errors, function (key, value) {
                     if ('errors' in value) {
                         $.each(value.errors, function () {
                             message += this + "\n";
                         });
                     }
                 });
                 alert(message);
             }
         }
</script>

2 Answers, 1 is accepted

Sort by
0
Bill
Top achievements
Rank 1
answered on 24 Nov 2012, 06:05 AM
I was able to find a solution but it had nothing to do with the Client Template. I just built out the rest of the model properties to include the other fields. This still doesn't explain why GroupDescription did not have this problem. Does it have something to do with the fact that GroupName is required?

.DataSource(dataSource => dataSource
                   .Ajax()
                   .Model(model =>
                           {
                               model.Id(p => p.GroupId);
                               model.Field(p => p.GroupDescription);
                               model.Field(p =>p.GroupName);                              
                           })

public class GroupVM
    {
        public int GroupId { get; set; }
        [Required(ErrorMessage="Name is required")]
        public string GroupName { get; set; }
         
public string GroupDescription { get; set; }
        public Guid UserId { get; set; }       
    }
0
Vladimir Iliev
Telerik team
answered on 29 Nov 2012, 07:24 AM
Hi Bill,

 
I tried to reproduce the problem locally but to no avail – all properties are received correctly on the server with the Required attribute applied. Please provide run-able project where the issue is reproduced – hopefully this will help us pinpoint the exact reason for this behavior.

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Bill
Top achievements
Rank 1
Answers by
Bill
Top achievements
Rank 1
Vladimir Iliev
Telerik team
Share this question
or