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

can't get Model in EditorTemplate

4 Answers 298 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
xu
Top achievements
Rank 1
xu asked on 13 Jul 2012, 07:37 AM
    

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?

 

4 Answers, 1 is accepted

Sort by
0
Dennis
Top achievements
Rank 1
answered on 15 Jul 2012, 10:09 PM
In your UserEditor.cshtml file include at the tope of your page:

@model RoleModel

 

 

0
Joe
Top achievements
Rank 1
answered on 17 Jul 2012, 09:25 PM
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...
0
xu
Top achievements
Rank 1
answered on 19 Jul 2012, 01:18 AM
thanks!
0
Jero
Top achievements
Rank 1
answered on 20 Sep 2012, 07:28 AM
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. 
Tags
General Discussions
Asked by
xu
Top achievements
Rank 1
Answers by
Dennis
Top achievements
Rank 1
Joe
Top achievements
Rank 1
xu
Top achievements
Rank 1
Jero
Top achievements
Rank 1
Share this question
or