2011-01-21 9 views
9

Tengo un archivo en mi carpeta de vista Users llamado UserViewControl.cshtml.RenderPartial control en la misma carpeta de vista

Mi código en la vista real (Users.cshtml) es:

@Html.RenderPartial("RegisterViewControl") 

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

no quiero que escribir la ruta completa como ésta en su conjunto las carpetas de vista puede moverse en el futuro :

@Html.RenderPartial("~/Views/Users/RegisterViewControl.cshtml") 

Código de RegisterViewControl.cshtml:

@model SampleMVC.Web.ViewModels.RegisterModel 

@using (Html.BeginForm("Register", "Auth", FormMethod.Post, new { Id = "ERForm" })) 
{ 
    @Html.TextBoxFor(model => model.Name)   
    @Html.TextBoxFor(model => model.Email)    
    @Html.PasswordFor(model => model.Password)   
} 

Esta es una forma que será presentado por el Ajax, pero quiero toda la validación del modelo de vista.

+0

por favor, puesto el código dentro de UserViewControl.cshtml – Clicktricity

+0

@Clicktricity agregado. –

Respuesta

23

Debería ser así:

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

Y eso es porque el método RenderPartial extensión no devuelve nada. Escribe directamente en la salida. En aspx que lo utilice como esto:

<% Html.RenderPartial("RegisterViewControl"); %> 

en lugar de:

<%= Html.RenderPartial("RegisterViewControl") %> 

lo que se aplican las mismas reglas para la maquinilla de afeitar.

7

Se podría, alternativamente, utilizar

@Html.Partial("RegisterViewControl") 
0

tuve este problema también y conseguido esto directamente desde el blog de Scott Guthrie:

using @Html.RenderPartial() from a Razor view doesnt work.

Rather than call Html.RenderPartial() use just @Html.Partial("partialname")

That returns a string and will work.

Alternatively, if you really want to use the void return method you can use this syntax:

@{Html.RenderPartial("partialName")}

But @Html.Partial() is the cleanest.

El enlace para esto es: http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx

Cuestiones relacionadas