Is it possible to store and then retrive MVC tags inside a database?
Suppose I want to store a link like this one - @Url.Action("link text", "SomeAction", "HomeController) - in an NVARCHAR field in my database. How do I code this in Razor so that it will produce a link pertaining to that example?
cnlayibme
Member
45 Points
66 Posts
MVC/Razor tags inside a database
May 17, 2012 07:29 AM|LINK
Is it possible to store and then retrive MVC tags inside a database?
Suppose I want to store a link like this one - @Url.Action("link text", "SomeAction", "HomeController) - in an NVARCHAR field in my database. How do I code this in Razor so that it will produce a link pertaining to that example?
urenjoy
Star
12193 Points
1825 Posts
Re: MVC/Razor tags inside a database
May 17, 2012 07:44 AM|LINK
I think It can be done using Razor.Parse with Your razor syntax as string.
http://ultimatetutorial.com/2011/11/using-razor-template-outside-mvc/
http://stackoverflow.com/questions/7523918/asp-net-mvc-execute-razor-from-db-string
cnlayibme
Member
45 Points
66 Posts
Re: MVC/Razor tags inside a database
May 17, 2012 08:26 AM|LINK
Thank you for the suggestion. I am very new to this. Yet I still tried it. But it just added an ";" to the last part of the supposed output.
What I did was installed the RazorEngine and then in my view I coded : @RazorEngine.Razor.Parse(item.contentFromDatabase)
Or maybe I just coded it wrong.
Young Yang -...
All-Star
21344 Points
1818 Posts
Microsoft
Re: MVC/Razor tags inside a database
May 24, 2012 01:46 AM|LINK
You need to write a custom VirtualPathProvider and register it within the ASP.NET hosting environment. There is an example that does exactly what you're looking for: http://www.umbraworks.net/bl0g/rebuildall/2009/11/17/ASP_NET_MVC_and_virtual_views and you also could refer to: http://haacked.com/archive/2009/04/22/scripted-db-views.aspx
Hope this helpful
Regards
Feedback to us
Develop and promote your apps in Windows Store