asp.net mvc - Can one MVC Edit Template delegate to another? -


i have strongly-typed razor 2 editor template. when view model meets conditions, want view delegate alternative template of same type. use templatename argument editorfor helper select alternative template:

@model mytype @if (model.isspecialcase) {     @html.editorfor(m => m, "specialcasetemplate") } else {     @* default markup *@ } 

problem is, razor not call alternative template; passes on editorfor method. if change type of second template, shows correctly. can work around using partial view, rather not, have scheme going editor templates want stick to.

anyone know how can work?

edit

looks has behaviour described here: asp.net mvc - using editorfor same model type twice. in short, mvc not support using editorfor method on same object twice.

the best way this, returning different view controller:

public actionresult someaction(){     var model = ...;     if (model.isspecialcase){         return view("specialcasetemplate");     }     else{         return view();     } } 

alternatively, in view this:

@model mytype @if (model.isspecialcase) {     html.renderpartial("specialcasetemplate", model); } else {     @* default markup *@ } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -