can't get Model in EditorTemplate

5 posts, 0 answers
  1. xu
    xu avatar
    17 posts
    Member since:
    Jul 2010

    Posted 13 Jul 2012 Link to this post

        

    public

     

    class UserModel

     

    {

     

        public

     

    IEnumerable<RoleModel> RoleModels { get; set; }

     

    }

    public

     

    class RoleModel

     

    {

     

        public int Id { get; set; }

     

     

        public string Name { get; set; }

     

     

        public bool InRole { get; set; }

     

    }
    ~User.cshtml
    @(Html.Kendo().Grid<Mrjiou.Models.UserModel>()

     

    .Name(

    "Grid")

     

    .Editable(editable => {

    editable.Mode(

    GridEditMode.PopUp).TemplateName("UserEditor"); })

     

    .Columns(columns =>

    {

    columns.Bound(u => u.Name);

    columns.Command(command => {

    command.Edit();

     

    })

     

     

    .DataSource(dataSource => dataSource

    .Ajax()

    .Model(model => model.Id(m => m.Id))

    .ServerOperation(

    false)

     

    .Read(read => read.Data(

    "additional_data").Action("User_Read", "User"))

     

     

    .Update(update=>update.Action("User_Update", "User"))

     

     

    )

    ~UserEditor.cshtml:
    @Html.LabelFor(m => m.Name)

     

    @Html.EditorFor(m => m.Name)

     

    @Model.RoleModels.Count()

     

    @Html.EditorFor(m => m.RoleModels,

    "UserRoleEditor")

    the problem is i can't get RoleModels in UserEditor.cshtml,it's alway null. what's the problem?

     

  2. Dennis
    Dennis avatar
    38 posts
    Member since:
    Aug 2012

    Posted 15 Jul 2012 Link to this post

    In your UserEditor.cshtml file include at the tope of your page:

    @model RoleModel

     

     

  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Joe
    Joe avatar
    34 posts
    Member since:
    Jul 2012

    Posted 17 Jul 2012 Link to this post

    Yeah I am pretty sure the model is always empty when using Ajax binding, you would need to use server binding to get the actual model into your editor template. Makes me about as happy as you...
  5. xu
    xu avatar
    17 posts
    Member since:
    Jul 2010

    Posted 18 Jul 2012 Link to this post

    thanks!
  6. Jero
    Jero avatar
    7 posts
    Member since:
    Apr 2012

    Posted 20 Sep 2012 Link to this post

    It is confirmed that is not possible to access the model from the template??? I don't want to change to server mode, I need to use AJAX binding. 
Back to Top
UI for ASP.NET MVC is VS 2017 Ready