2

我有一个强类型的部分视图,应该显示用户登录的帐户名称:


@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.

我是否至少朝着正确的方向前进?

4

1 回答 1

10

您必须删除controller通话中的部分

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

要渲染局部视图,您还可以调用

 @Html.Partial("AccountName", "AccountName", Model)
于 2012-04-27T12:46:31.250 回答