Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC3 @Html.RenderPartial is throwing CS1502 Error

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?

like image 899
berwyn Avatar asked Nov 10 '11 05:11

berwyn


People also ask

What is HTML RenderPartial?

RenderPartial(HtmlHelper, String) Renders the specified partial view by using the specified HTML helper. RenderPartial(HtmlHelper, String, Object) Renders the specified partial view, passing it a copy of the current ViewDataDictionary object, but with the Model property set to the specified model.

What is the difference between Render () and RenderPartial ()? Write the syntax?

Renderpartial does exactly the same thing and is better for performance over partial(). The main difference between Partial and RenderPartial is : Partial return string and write it to document as Shweta said . RenderPartial actually write direct to context response. Html.

What is difference between HTML partial and HTML RenderPartial in MVC?

The primary difference between the two methods is that Partial generates the HTML from the View and returns it to the View to be incorporated into the page. RenderPartial, on the other hand, doesn't return anything and, instead, adds its HTML directly to the Response object's output.

What is the difference between RenderPartial and RenderAction?

RenderPartial is used to display a reusable part of within the same controller and RenderAction render an action from any controller. They both render the Html and doesn't provide a String for output.


1 Answers

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

@Html.Partial("_AddressPartial")

or

@{ Html.RenderPartial("_AddressPartial"); }
like image 57
Marc Gravell Avatar answered Oct 03 '22 03:10

Marc Gravell