Is it possible to use DisplayFor() from within the EditorFor template control

前端 未结 2 1193
傲寒
傲寒 2020-12-18 05:48

I am using EditorFor() helper to render edit template in my view and I would like to call the DisplayFor() inside this template to render out the D

相关标签:
2条回答
  • 2020-12-18 06:20

    I am afraid that the only way is to use a partial:

    <%= Html.Partial("~/Views/Home/DisplayTemplates/Client.ascx", Model) %>
    
    0 讨论(0)
  • 2020-12-18 06:31

    It can be debatable if it is a good idea to template complicated objects, or if my approach to nested templates is a hack or not. The advantage of this is having a single template for the parent and child can both have templates rather than having to choose/use partial views.

    All that aside, templated views can be nested, if you use a partial view as an go between.

    The outside template will have something like below where you want to place the inner template:

    Html.RenderPartial("SharedDisplayGoBetweenForFoo", item);  
    

    The shared partial would look like this:

    @model Foo
    
    @Html.DisplayFor(a => a);
    

    The inner template would then be called and would look like any other.

    0 讨论(0)
提交回复
热议问题