I’m trying to understand why when I do this in my view, I get an error
@Html.RenderPartial("MyPartial", Model);
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1502: The best overloaded method match for ‘System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)’ has some invalid arguments
But when I do this, the partial renders fine
@{
Html.RenderPartial("MyPartial", Model);
}
Does anyone know why the first example fails?
It’s basically the fact that this format…
… is used for functions that don’t return
void, since RenderPartial does returnvoid, you get that error.Instead, in this block, it’s just code execution (that will internally make the write call):
You can alternativelly call
… which does return the string.