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

Model is null on Post to Controller

2 Answers 524 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Abdul
Top achievements
Rank 1
Abdul asked on 19 Jun 2014, 02:30 PM
Hey!

I'm creating a view, based on a ViewModel. This View Model has two Complex Properties, of which one is collection

 public class SecurityTemplateViewModel
    {
        public SecurityTemplate secTemp { get; set; }
        public List<SecurityListViewModel> secList { get; set; }
    }

Second Property (viz. secList) is collection which displays two columns in grid(Description, Action, Rest are hidden). Action is a list of CheckBoxes.

Action Method to fill the View is:

public ActionResult Create()
        {
            SecurityTemplateViewModel secTempVM = new SecurityTemplateViewModel();
                                     var securityList = _secTemp.GetSecurityList();
            secTempVM.secList = securityList;
 
            return View(secTempVM);
        }

Razor Code which Renders Kendo Grid is:

  @(Html.Kendo().Grid(Model.secList)
    .Name("secList")
    .Columns(columns =>
    {
        columns.Bound(p => p.SecurityListId).Hidden();
        columns.Bound(p => p.HubId).Hidden();
        columns.Bound(p => p.FormId).Hidden();
        columns.Bound(p => p.DataActionId).Hidden();
        columns.Bound(p => p.Description).Width(450).Filterable(true);
        columns.Bound(p => p.Action).Width(50).Sortable(false).Filterable(false);
       .HeaderTemplate("<div align=center><p>Select All </p><input id='selectall' type='checkbox'  checked= 'checked' /></div>")
        .ClientTemplate("<div align=center><input type='checkbox'  checked='checked' /></div>"); 
    })
         .DataSource(dataSource => dataSource
            .Ajax()
            .ServerOperation(false)
           .Model(model =>
            {
                model.Id(p => p.SecurityTemplateId);
                model.Field(p => p.Description).Editable(false);
                model.Field(p => p.Action).Editable(true);

            }))
     .Sortable()
    .Scrollable()
    .Filterable()
    .HtmlAttributes(new { style = "height:530px;" })
    );

All i need from grid to show Description and List of Checkboxes. Logic of Insertion is on Action (Post) in Controller. 
My Issue is I'm able to display gird, but when I try to access this collection on Create (Post), the model Property (secList) is null. Can you please advise from where I'm getting it wrong?





2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 23 Jun 2014, 01:09 PM
Hello Abdul,

ASP.NET MVC model binding needs a special syntax for binding a collection of objects. You can check this stackoverflow answer which shows how this can be done with the kendo grid: http://stackoverflow.com/questions/14555137/submit-form-with-kendo-mvc-grid-and-other-elements

In short you should properly set the name of the checkbox in the grid template.

Regards,
Atanas Korchev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Abdul
Top achievements
Rank 1
answered on 23 Jun 2014, 02:13 PM
Thanx Atanas!

Actually, I did get the issue and got it done but without Kendo. What I didn't know was how to index the collection in Kendo. Links seems to contain the answer..

Thank you!
Tags
Grid
Asked by
Abdul
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Abdul
Top achievements
Rank 1
Share this question
or