Reputation:
I'm building my first ASP.NET MVC application and I am having some troubles with Partial Views.
If I, as an example, want to put a "Footer" as a Partial I create an "MVC View User Control" in "/Views/Shared/Footer.ascx". (I leave it empty for now)
What is the correct way for adding it to my Layout?
I have tried:
<%=Html.RenderPartial("Footer")%>
and:
<%=Html.RenderPartial("~/Views/Shared/Footer.ascx")%>
For each one I get an exception:
"CS1502: The best overloaded method match for 'System.IO.TextWriter.Write(char)' has some invalid arguments"
What is the correct way to deal with partials in ASP.NET MVC?
Upvotes: 11
Views: 3287
Reputation: 5377
Do what @BenScheirman said, and add a semi-colon at the end of your statement :)
<% Html.RenderPartial("~/Views/Shared/Footer.ascx"); %>
Update: I guess VB doesn't require the semi-colon. So you would only need that if you are programming in C#.
Upvotes: 13
Reputation: 40961
In this case don't use the <%= syntax. Just use the <% %> syntax. Then the first form in your examples should work.
For more info, check here: http://bradwilson.typepad.com/blog/2008/08/partial-renderi.html
Upvotes: 23