views:

1385

answers:

2

I'm building my first ASP.NET MVC application and I am having some troubles with Partial classes.

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?

+18  A: 

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

Ben Scheirman
+10  A: 

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#.

Ricky
The author of the question is most probably coding in VB.NET. Semi-colons are not a part of the VB.NET language.
RodgerB
that is your assumption I guess. Thanks for the down vote !
Ricky
I think the CS compiler error is a hint at C# being used here...http://msdn.microsoft.com/en-us/library/b66k5sz9(VS.71).aspx
Codewerks
Whoops, thanks for the catch Ricky. (and no, I'm NOT programming in VB.NET)
Ben Scheirman