0

I would like to create a HTML helper that works the same as Html.RenderPartial except I would like the partial to be rendered from ViewData or a model object and not a file on the filesystem.

example: <% Html.RenderVirtualPartial("Name", Model.MyPartialContent") %>

I can return string in my helper but i need to have code tags (ie <%= DateTime.Now %>) interpreted so assume I need do some kind of binary output stream writer?

thanks in advance

-Mark

Mark
  • 6,051
  • 2
  • 26
  • 25
  • What is the reason behind this? – Mattias Jakobsson Mar 05 '10 at 11:58
  • Because I want re-usable content that can be edited from a backend and which is able to make use of other helper methods i create. think similar to virtualpathprovider in terms of content stored in a database. Thanks -Mark – Mark Mar 05 '10 at 12:06
  • Ok. For this to work you will have to parse and compile the code as you have c# code in a string. This will probably be quite a lot of work. I know the spark viewengine does something like that for its views. Maybe you can check out that project and find a solution. – Mattias Jakobsson Mar 05 '10 at 12:31
  • I think I'm looking for something like this but not sure how to get it to work like ive stated above: http://stackoverflow.com/questions/483091/render-a-view-as-a-string/1241257#1241257 – Mark Mar 05 '10 at 12:48
  • That will not really help you. That does the other way around as to what you want to do. So it doesn't have any c# code in any string that it needs to compile. I suggest you do this some other way. Maybe edit the actual .ascx file instead. If you are thinking of this for a cms or something you should rethink anyway as it will be a huge security risk as you let the user do whatever he wants (he could very easily take control of your database for example). – Mattias Jakobsson Mar 05 '10 at 12:56

1 Answers1

0

why not add the futures and you can use renderAction, or you can render partial put pass a model over also

davethecoder
  • 3,856
  • 4
  • 35
  • 66