asp.net mvc - How could I render a view containing custom display templates into a compiled view? -
my mvc view makes calls html.displayfor() , display templates within make calls other html.displayfor(). i need render type of view contains custom display templates string, wrote method this:
public static string renderrazorview(dynamic model, string viewpath, httpcontextbase httpcontextbase) {     using (var sw = new stringwriter())     {        viewdatadictionary viewdata = new viewdatadictionary();        viewdata.model = model;         controllercontext controllercontext = new controllercontext(new requestcontext(httpcontextbase, routetable.routes.getroutedata(httpcontextbase)),  new tempcontroller());             razorview view = new razorview(controllercontext, viewpath, null, false, null);             view.render(new viewcontext(controllercontext, view, viewdata, new tempdatadictionary(), sw), sw);             return sw.getstringbuilder().tostring();         }     }   and called in way:
var bookdisplay = new bookdisplaymodel(model);     var data = renderrazorview(bookdisplay,          $"~/themes/admin/theme1/views/book/preview.cshtml", utilities.gethttpcontextbase(siteuri/admin")));   it seems renderview() , render() method in razorview class using default display templates , rendering custom display templates doesn't occur.
 
 
wiki
 
  
Comments
Post a Comment