Reputation: 1439
I have my user control in a class library and I have a public method in it which returns the user control as html string. I want to display this HTML in my MVC view. I am using the following code in my view:
<div>
<% MyControlsNamespace.MyControl mvc = new MyControl();
mvc.LoadMyControl(); %>
</div>
LoadMyControl() returns html as string. I can't see any thing in my view when I open it in a browser. I am new to MVC and I knew I am missing some thing here. Any guess??? I am using MVC1
Upvotes: 0
Views: 814
Reputation: 155145
Use <% Html.RenderPartial("Path/To.ascx") %>
or <%= Html.Partial("Path/To.ascx") %>
.
Use RenderPartial
when you're fine with the user-control rendering directly to the response stream, or use Partial
if you want to intercept the output as an MvcHtmlString. RenderPartial
is faster and generally preferred, only use Partial
if you know you need the MvcHtmlString.
More information is available here: Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction
Upvotes: 2