Compiling a spark expression within a string -


i have asp.net mvc2 application within trying use spark view engine render input string, e.g.:

"!{html.actionlink(\"a link\", \"index\")} followed text" 

i run problems when trying utilize htmlhelpers. spark compiler returns error 'the name 'html' not exist in current context'. full method below:

    public actionresult index()     {         var templates = new inmemoryviewfolder();         var engine = new sparkviewengine() { viewfolder = templates };          var stringresult = new stringbuilder();         stringresult.appendline("!{html.actionlink(\"a link\", \"index\")} followed text");          templates.add("string.spark", stringresult.tostring());          var descriptor = new sparkviewdescriptor().addtemplate("string.spark");         var view = engine.createinstance(descriptor);         var result = new stringbuilder();         stringwriter sw = new stringwriter(result);         view.renderview(sw);          return content(result.tostring());     } 

i have had success if create index.spark file within views folder, using system.web.mvc.viewengines, , utilize htmlhelpers there, guessing there missing setup of sparkviewengine within index method above.

i cannot put these contents file assembling them @ runtime.

thank in advance!

you need add namespaces/assemblies spark engine, doesn't automatically add system.web , others (you construct manually , have specify config manually, won't read web.config). you'll need provide httpcontext, because htmlhelper won't work without it. sorry can't remember in details how should done, refer here how setup assemblies/namespaces.

but easier if provide view data (view model) instead. either pass base url parameter, or pass function (method of view model, func<>) view invoke construct required url. way, specify master template in-memory engine re-define entities, i.e. set html custom memoryhtmlhelper contain same methods such actionlink, work without httpcontext.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -