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

referencing the current enumerated object of the gird, editor templates

6 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 16 Jul 2013, 09:55 AM
Hi, 
    I am trying to render a different partial view based on a property of the model. I will then need to pass the model from the current enumeration to the Html.RenderPartial called in the template 

as below i need to pass the current model from the edit to the RenderPartial i.e. "themodel".  How do I get the syntax to pass the model to it?

Thanks 

@using Assessments.Models;
@model IEnumerable<FallsAssessment>
 
@{
    ViewBag.Title = "FallsAssessmentList";
}
 
<h2>FallsAssessmentList</h2>
@Html.Kendo().Grid(Model).Name("FallsAssessments").Columns(columns=>
    {
        columns.Bound(m => m.AssessmentType).Title("Assessment Type");
        columns.Bound(m=> m.Ward).Title("Ward");
        columns.Bound(m=>m.LastUpdated_TS).Title("Last Updated");
        columns.Bound(m => m.LastUpdatedBy).Title("User");
        columns.Bound(m => m.Score);
        columns.Command(m => m.Edit().Text("Edit"));
    }
    ).ToolBar(t=>t.Create()).DataSource(d=>d.Ajax()
        .Model(
            model=>
                {
                    model.Id(id=>id.EventID);
                    model.Field(field=>field.EventID).Editable(false);
                }).Create("Create", "FallsAssessment").Update("Update", "FallsAssessment")).Editable(e => e.Mode(GridEditMode.PopUp).TemplateName("edit-template"))
               
 
              FallsAssessmentFallsAssessmentFallsAssessment
 
<script id="edit-template" type="text/x-kendo-template">
#if(AssessmentType=='Child'){#
@Html.RenderPartial("AdultAssessment",themodel)
#}else{#
@Html.RenderPartial("AdultAssessment", themodel)
#}
</script>

6 Answers, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 17 Jul 2013, 09:05 AM
Hi, is there any update to this? is it possible to do?
0
Daniel
Telerik team
answered on 18 Jul 2013, 07:55 AM
Hello,

The model cannot be passed to the PartialView helper when using Ajax binding. The helper is executed on the server and the model is loaded on the client via Ajax. In order to pass the model you should use a server detail template. Another option would be to load the content via Ajax in the detailInit event or with a widget that supports loading the content via Ajax as the tabstrip. An alternative solution would be to use the template syntax to populate the model values in the partial views.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
David
Top achievements
Rank 1
answered on 18 Jul 2013, 08:17 AM
The server templates look ideal.. but the issue is I can't see how to use them for an edit item...  Is it possible?

currently I am having to build up my own custom ajax link to post to the controller to render the view I wan't in a custom modal popup.... I don't like it as the Ajax html helpers don't work correctly in the grid and it all has to be done with strings. 



0
Daniel
Telerik team
answered on 22 Jul 2013, 07:22 AM
Hello,

Sorry, I misunderstood the previous question. If the partial view should be used for editing then you should use server editing and use the conditional logic in the EditorTemplate:

@model MyModel
 
@if(Model.Field)
{
    Html.RenderPartial("FirstPartial", Model);
}
else
{
    Html.RenderPartial("SecondPartial", Model);   
}
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
David
Top achievements
Rank 1
answered on 23 Jul 2013, 07:52 AM
Hi Daniel, 
                  Yes a new that I could create a template just to have the logic on which partial view to display.  At the time of posting I could see that people were accessing the properties of the model in the teplating javascript syntax. So I was hoping not to have to follow that and use a view/EditorTemplate just for a conditional statement. 

I settled for a custom ajax action link to call a controlled which passed back the correct partial view to display, and rendered it in a bootstrap modal. 

It in hindsight creating the custom server template as you suggested may have saved some time with the java script I needed. 

I will be happy to mark this as answered as I think we have covered all the scenarios to get this working.

Thanks

David  
0
Daniel
Telerik team
answered on 25 Jul 2013, 06:33 AM
Hello David,

In the editor template it is possible to bind the elements in order to access the value when using Ajax editing and for popup editing, it is also possible to access the values with a template expression(${} in this case). In both cases however, the values will be available on the client and so a server side method cannot be used.

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