11

I'm building an MVC3 app for my dynamic web class, and while attempting to render a partial, I get the following error:

CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments

Now, the code I'm executing is this:

<div>
    <h2>Shipping Address</h2>
    @Html.RenderPartial("_AddressPartial");
</div>

Now, I've googled this, and from what I've seen, the answers are all for older versions of MVC and used the <% %> style syntax and got System.IO errors rather than the System.Web error I'm getting. I did follow their advice though and try with and without the semicolon, which made no difference as I still got the YSOD each time. Any ideas?

2
  • Is the Web.Config been modified in any way? Commented Nov 10, 2011 at 6:05
  • Web.Config was only modified for a DB connection string and an API key for my credit card processor, otherwise is the one generated when I created the project Commented Nov 10, 2011 at 6:50

2 Answers 2

26

This might just be because RenderPartial doesn't return anything. Try either:

@Html.Partial("_AddressPartial")

or

@{ Html.RenderPartial("_AddressPartial"); }
Sign up to request clarification or add additional context in comments.

1 Comment

Using the @{ Html.RenderPartial("_AddressPartial"); } version worked! Thanks a ton!
6

Notice that RenderPartial doesn't return any value (just like the RenderAction method), it writes the output on the request. while Partial (just like the Action method) return value of MvcHtmlString.
SO @Html... has to return some value while @{...some code...} doesn't have to.
In your case if you want to use renderPartial use it like that:

@{Html.RenderPartial("_AddressPartial");}

But why not use the Partial method, which you can use like that:

@Html.Partial("_AddressPartial")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.