Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Derik Whittaker

Thoughts on Software Development, .Net, OOP, Design Patterns and all things cool



Asp.Net RenderPartial Exception - CS1502

If you are trying to use the HTML Helper RenderPartial and you received the following error:

CS1502: The best overloaded method match for 'System.IO.TextWriter.Write(char)' has some invalid arguments error

do worry, you are not alone.  When I was trying to upgrade DimeCasts.Net to Preview 5 I was getting this error.  What was really odd, was that the exception and stack trace did not really make sense.  It was not till I read Brad Wilson's blog did I realize what the issue was.

Take a look at the following code:

<%= Html.RenderPartial("somecontrol.ascx",  SomeDataEntity )  %>

What you will notice is that the code above has an = sign in the markup.  I left this because I converted this code from Html.RenderUserControl which needed the '=' as it returned a string.  Since RenderPartial is void method you do NOT NEED the '='.

Try removing the '=' sign and see if your issue goes away.

The correct code would be:

<% Html.RenderPartial("somecontrol.ascx",  SomeDataEntity )  %>

Hope this helps someone else.

Till next time,

[----- Remember to check out DimeCasts.Net -----]



Comments

nick berardi said:

thanks you probably just saved me an hour and half my hair.

# August 30, 2008 8:40 PM

ASP.NET MVC Preview Release 5 - Nick Berardi’s Coder Journal said:

Pingback from  ASP.NET MVC Preview Release 5 - Nick Berardi&#8217;s Coder Journal

# August 31, 2008 8:53 AM

IHateSpaghetti {code} said:

ASP.NET A solution for the partial rendering issue: CS1502: The best overloaded method match for &#39;System

# August 31, 2008 11:42 AM

Tim Barcz said:

This is going to save me a ton of time when I upgrade our code this weekend.

# September 4, 2008 10:56 PM

Dragan Panjkov said:

Let's be precise. Correct code doesn't have to contain .ascx extension at the end, only name of partial view and a semicolon on the end

<% Html.RenderPartial("somecontrol",  SomeDataEntity );  %>

# September 7, 2008 6:04 PM

Baldev Rawat said:

Thanks a lot. I was struggling to solve this problem. Your post has saved my lot of time.

# September 21, 2008 11:33 AM

Matt Cole said:

A thanks from me too :)

# September 30, 2008 11:29 AM

Mahabub Sikder said:

Its really helpful !

Thanks a lot

# October 14, 2008 10:44 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Derik Whittaker

Derik is a .Net Developer/Architect specializing in WinForms working out the northern suburbs of Chicago. He is also believer and advocate for Agile development including SCRUM, TDD, CI, etc.

When Derik is not writing code he can be found spending time with his wife and young son, climbing on his bouldering wall, watching sports (mostly baseball), and generally vegging out. Check out Devlicio.us!

Our Sponsors

Red-Gate!