开发者

dynamically creating view inside another view in mvc 3

I have downloaded an html file as stream object and and and i have to render a partial view in a particular tag inside the html file . All the html file along with the partial view will be shown as a preview inside a view under a preview tag section. I am able to find a div tag inside the html f开发者_运维问答ile and i set the user control div's inner html. The code i used is

 header.InnerHtml = " <%:Html.RenderPartial(" + "\"/ViewUserControl1" + "\"); %> "; 

where "header" is the id of the div . and pass entire string to(html along with usercontrol ) to view using

<div id="Preview" >
    <%=ViewData["Preview"] %>
</div>

But the div preview dosent render user control. only html file preview is shown. Any ideas will be grately appreciated.

Thanks in advance


Strings will not be parsed as view code unless you do a bunch of extra work - that would be a huge security hole. Even if you set up parsing of the string, the rest of the html won't be valid view code.

The best option would be to just use a token in the html - "{VIEW}" or something like that - and do a string replace in your view using the template html and view name properties from the model.

Also note the difference between Html.Partial and Html.RenderPartial - one returns a string, the other writes to the output stream and returns nothing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜