2012-04-27 72 views
2

我有应显示的帐户的名称,它是用户登录到一个强类型的局部视图:与@ HTML.Action(...)局部视图


@model MyNamespace.Models.AccountNameViewModel 

@if (Request.IsAuthenticated) 
{ 
    @Html.Action("AccountName", "AccountNameController", Model) 
    Logged in to @Model.AccountName 
} 
 

我有一个控制器:

public class AccountNameController : Controller 
{ 
    public ActionResult Index() 
    { 
     return View(); 
    } 

    [ChildActionOnly] 
    public ActionResult AccountName(AccountNameViewModel model) 
    { 
     ... Do somthing with the repository to populate the model 
     return PartialView(model); 

    } 
} 

我想要做的是添加一个共享的局部视图,显示用户登录的帐户的名称。我得到的是以下错误:

The controller for path '/ParentViewPath/' was not found or does not implement IController. 

我是否至少前往正确的方向?

回答

8

您必须在您的通话

@Html.Action("AccountName", "AccountName", Model) 

要渲染的局部视图删除controller一部分,您也可以拨打

@Html.Partial("AccountName", "AccountName", Model) 
+0

应该是很明显... – Void 2012-04-27 13:05:12