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

Asp.Net MVC Razor. Binding Grid data back to model property

0 Answers 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vladimir
Top achievements
Rank 1
Vladimir asked on 21 Jun 2017, 04:28 PM

Hi!

On Razor View i`m trying to bind Grid to ExcludedAffiliations property of EntertainerModel:

public class EntertainerModel : BaseNopEntityModel

{

    public int Id { get; set; }
    public string Description { get; set; }

...
   public GridModel<ExcludedAffiliationModel> ExcludedAffiliations { get; set; }
}

public class ExcludedAffiliationModel : BaseNopEntityModel
{
        public int Id { get; set; }
        public string Name { get; set; }
        public bool Excluded { get; set; }
}

View definition:

    @(Html.Telerik().Grid<ExcludedAffiliationModel>(Model.ExcludedAffiliations.Data)
                    .Name("entertainer-excluded-affiliation-grid")
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.Excluded)
                        .Width(15)
                        .Centered()
                        .Template(x => Html.CheckBox("chbxAffiliationExcluded" + x.Id, x.Excluded, new { @class = "apply-affiliation-excluded", affiliationId = x.Id, entertainerId = Model.Id }))
                        .ClientTemplate("<# if (Excluded == true)  { #> <input value='true' type='checkbox' checked='checked' id='chbxAffiliationExcluded<#= Id #>' affiliationId='<#= Id #>'  entertainerId = '<#= Model.Id #>' class='apply-affiliation-excluded' /> <# } else { #> <input type='checkbox' id='chbxAffiliationExcluded<#= Id #>' affiliationId ='<#= Id #>' entertainerId = '<#= Model.Id #>' class='apply-affiliation-excluded' /> <# } #>");

                        columns.Bound(x => x.Id)
                        .Width(100)
                        .Centered()
                        .ReadOnly();

                        columns.Bound(x => x.Name)
                        .Width(250)
                        .ReadOnly();
                    }))

Controller action method:

public ActionResult Edit(EntertainerModel model, bool continueEditing)
{

...

}

As a result i see the grid with three columns and can click checkbox in the column "Excluded".

But when i click standard submit button on the page, action method of controller called but the property ExcludedAffiliations of the model is null.

My question is: is it exists a way for binding grid data back to model property ?

Thanks a lot.

 

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Vladimir
Top achievements
Rank 1
Share this question
or