与@ HTML.Action局部视图(...) [英] Partial view with @HTML.Action(...)

查看:523
本文介绍了与@ 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

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

要渲染的局部视图,你也可以拨打

To render a partial view you can also call

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

这篇关于与@ HTML.Action局部视图(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆