我有一个强类型的局部视图,应该显示用户登录的帐户的名称:
@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.
我是否至少朝着正确的方向前进?
答案 0 :(得分:9)
您必须删除通话中的controller
部分
@Html.Action("AccountName", "AccountName", Model)
要渲染局部视图,您还可以调用
@Html.Partial("AccountName", "AccountName", Model)