MVC/Razor tags inside a databasehttp://forums.asp.net/t/1804593.aspx/1?MVC+Razor+tags+inside+a+databaseThu, 24 May 2012 01:46:44 -040018045934984724http://forums.asp.net/p/1804593/4984724.aspx/1?MVC+Razor+tags+inside+a+databaseMVC/Razor tags inside a database <p>Is it possible to store and then retrive MVC tags inside a database?</p> <p>Suppose I want to store a link like this one - @Url.Action(&quot;link text&quot;, &quot;SomeAction&quot;, &quot;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?</p> <p></p> 2012-05-17T07:29:48-04:004984749http://forums.asp.net/p/1804593/4984749.aspx/1?Re+MVC+Razor+tags+inside+a+databaseRe: MVC/Razor tags inside a database <p>I think It can be done using Razor.Parse with Your razor syntax as string.</p> <p><a href="http://ultimatetutorial.com/2011/11/using-razor-template-outside-mvc/">http://ultimatetutorial.com/2011/11/using-razor-template-outside-mvc/</a></p> <p>http://stackoverflow.com/questions/7523918/asp-net-mvc-execute-razor-from-db-string</p> <p></p> 2012-05-17T07:44:52-04:004984836http://forums.asp.net/p/1804593/4984836.aspx/1?Re+MVC+Razor+tags+inside+a+databaseRe: MVC/Razor tags inside a database <p>Thank you for the suggestion. I am very new to this. Yet I still tried it. But it just added an &quot;;&quot; to the last part of the supposed output.</p> <p>What I did was installed the RazorEngine and then in my view I coded : @RazorEngine.Razor.Parse(item.contentFromDatabase)</p> <p>Or maybe I just coded it wrong.</p> 2012-05-17T08:26:07-04:004994646http://forums.asp.net/p/1804593/4994646.aspx/1?Re+MVC+Razor+tags+inside+a+databaseRe: MVC/Razor tags inside a database <p>You need to write a custom <a href="http://msdn.microsoft.com/en-us/library/system.web.hosting.virtualpathprovider.aspx"> VirtualPathProvider</a> and register it within the ASP.NET hosting environment. There is an example that does exactly what you're looking for: <a href="http://www.umbraworks.net/bl0g/rebuildall/2009/11/17/ASP_NET_MVC_and_virtual_views"> http://www.umbraworks.net/bl0g/rebuildall/2009/11/17/ASP_NET_MVC_and_virtual_views</a>&nbsp;and you also could refer to: <a href="http://haacked.com/archive/2009/04/22/scripted-db-views.aspx">http://haacked.com/archive/2009/04/22/scripted-db-views.aspx</a></p> <p>Hope this helpful<br> Regards</p> 2012-05-24T01:46:44-04:00