Asp.net MVC-从区域渲染局部视图 [英] Asp.net MVC - Render a partial View From an Area

查看:182
本文介绍了Asp.net MVC-从区域渲染局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个区域,该区域将处理我们所有开发产品中的一些通用内容,例如登录,HTML帮助器等.在该区域中,我有一个局部视图,我试图在该视图之外进行引用该地区.我已经用

I've created an area that will handle our some generic things across all our development products, just as log ins, HTML helpers, etc. Inside the area, I have a partial view that I'm attempting to reference outside of the area. I've registered the area with

public class Routes : AreaRegistration
{
    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Common_default",
            "Common/{controller}/{action}/{id}",
            new {
                controller = "Account",
                action = "Index",
                id = UrlParameter.Optional
            });
    }

    public override string AreaName
    {
        get { return "MvcCommons"; }
    }
}

现在在常规项目中,我试图引用MvcCommons区域中的视图...

And now in the regular project, I'm trying to reference a view in the MvcCommons area...

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>TestGrid</h2>

<% Html.RenderPartial("jQGridTable", ViewData.Model); %>

但是我不断发现找不到该视图.以前,在创建MVC Commons项目时,我遇到了视图错误,但是这些错误告诉我,它同时在Area文件夹和默认视图文件夹中查找.这次,我仅获得默认文件夹.有什么办法可以做到这一点?

But I keep getting that the view isn't found. Before, while creating the MVC Commons project, I was getting view errors, but the errors told me that it looked in both the area folders and the default view folders. This time, I'm only getting the default folders. Is there any way to accomplish this?

谢谢大家!

推荐答案

我实际上并没有这样做,但是我猜测您应该使用Html.RenderAction()代替,例如Html.RenderAction("action", "controller", new { area = "Area", model = ViewData.Model }).

I haven't actually had to do this, but at a guess I would assume you should use Html.RenderAction() instead, something like Html.RenderAction("action", "controller", new { area = "Area", model = ViewData.Model }).

模型必须替换为动作参数的名称,但这应该可以工作.

model will have to be replaced with the name of the action's parameters, but that should work.

edit 这将需要一个控制器并查看每个动作的设置.

edit this will require a controller and view setup for each action though.

这篇关于Asp.net MVC-从区域渲染局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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