I have a web forms project, gone MVC. That means I have:
- A C# project with controllers and viewmodels
- A VB.NET Web Forms project, that has some views
All our logic is in the controllers, and in code behind from our Web From views, we call the controllers and use the viewmodels.
In my case, I have a ContentController
that does a lot of logic.
What I need to do is to render a user control and get the HTML. Problem is, I have not added the System.Web.UI DLL, and my partials are in the VB.NET project.
Therefore, I want to do the following:
In my viewmodel, i have a property called Content
. In my content I want to inject a string like this:
var res = "<%=Html.Render(\"~\\Views\\Products\\_ProductRecListItemView.ascx\", p)%>";
And then set a value called p
in my viewmodel, and then set that value like this:
ProductController productController = new ProductController();
var p_model = productController.Get("9788711401262");
model.p = p_model;
Now, my problem is when I layout this in a <p>@Model.Content</p>
, it obviously ends up looking like this as it is treated as a string on my page:
So my question is... How do I render this string as code, so I actually load my user control?
For reference, this is my "view":
<asp:Content ID="Content4" ContentPlaceHolderID="ContentMain" runat="server">
<div class="cmsSection">
<h1><%=Model.Headline%></h1>
<div>
<%=Model.Content%>
</div>
</div>
</asp:Content>