2011-01-21 18 views
9

UserViewControl.cshtml adlı Users görünüm klasörümdeki bir dosyam var.RenderParça görünümü aynı görüntüleme klasöründe

gerçek görüntüsü (Users.cshtml) My kodudur:

@Html.RenderPartial("RegisterViewControl") 

Hata: Gelecekte hareket olabilir tam tam görünüm klasör olarak böyle yolunu yazın istemiyorum The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments

:

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

Kod RegisterViewControl.cshtml yılında:

@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)   
} 

Bu, ajax tarafından sunulacak bir formdur, ancak tüm onaylamayı viewmodel'den istiyorum.

+0

gönderin UserViewControl.cshtml – Clicktricity

+0

@Clicktricity içindeki kod eklendi. –

cevap

23

Şöyle olmalı:

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

Ve RenderPartial uzatma yöntemi şey dönmez çünkü. Doğrudan çıktıya yazar. aspx size bu gibi kullanmak:

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

yerine:

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

Yani aynı kurallar ustura geçerlidir.

7

Alternatif bir yöntem olarak ben de bu sorunu vardı

@Html.Partial("RegisterViewControl") 
0

kullanmak ve Scott Guthrie blog yayınında bu doğrudan var olabilir:

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.

Bunun link

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

İlgili konular