c# - Create a View from String -


i experimenting in mvc 4, , wandering if possible turn string view , return controller.

for instance, have method reads view contents string. process string before rendering it. controller output modified string view.

is possible?

just make note, happen after razor has made changes. have method gets final view string.

edit

i have following method:

    public static string renderviewtostring(this controller controller, string viewname, object model)     {         controller.viewdata.model = model;         try         {             using (stringwriter sw = new stringwriter())             {                 viewengineresult viewresult = viewengines.engines.findview(controller.controllercontext, viewname, null);                 viewcontext viewcontext = new viewcontext(controller.controllercontext, viewresult.view, controller.viewdata, controller.tempdata, sw);                 viewresult.view.render(viewcontext, sw);                 viewresult.viewengine.releaseview(controller.controllercontext, viewresult.view);                    return sw.tostring();             }         }         catch (exception ex)         {             return ex.tostring();         }     } 

which returns rendered view (what going displayed in browser) string.

i need opposite. having string, output view.

so if have following cshtml:

<!doctype html> <head>     <title>@viewbag.title</title> </head> <body>     hello world </body> </html> 

the above function return string like:

"<!doctype html><head><title>myactualtitle</title></head><body>hello world</body></html>" 

now want take string, manipulate , render it. instance want change hello world. know can razor, wandering if can method.

yes possible:

public sealed class stringcontroller : controller {     //     // get: /string/     public string index()     {         return "hello world!";     } } 

if want razor process before returning, i'm not sure how that, don't need go via view that.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -