[英]Partial view with @HTML.Action(…)
I have a strongly typed partial view that should show the name of an account that a user is logged into: 我有一个强类型的局部视图,应该显示用户登录的帐户的名称:
@model MyNamespace.Models.AccountNameViewModel
@if (Request.IsAuthenticated)
{
@Html.Action("AccountName", "AccountNameController", Model)
Logged in to @Model.AccountName
}
I have a controller: 我有一个控制器:
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);
}
}
What I want to do is add a shared partial view that displays the name of an account that a user is logged into. 我想要做的是添加一个共享的部分视图,显示用户登录的帐户的名称。 What I get is the following error: 我得到的是以下错误:
The controller for path '/ParentViewPath/' was not found or does not implement IController.
Am I at least heading in the right direction? 我至少朝着正确的方向前进吗?
You have to remove the controller
part in your call 您必须在通话中删除controller
部分
@Html.Action("AccountName", "AccountName", Model)
To render a partial view you can also call 要渲染局部视图,您也可以调用
@Html.Partial("AccountName", "AccountName", Model)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.