的RenderPartial如何找出在哪里可以找到一个看法? [英] How does RenderPartial figure out where to find a view?

查看:142
本文介绍了的RenderPartial如何找出在哪里可以找到一个看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定。谷歌搜索可能会失败,我记得读这个而回,但无法找到它。

Ok. Googling fail probably and I remember reading about this a while back but can't find it.

我有一个观点,并在不同的目录下的局部视图。在一个视图我说 @ Html.RenderPartial([局部视图名称]); 如何做的RenderPartial找出去哪里找?它必须是一个惯例,但它是什么?

I have a View and a Partial View in different directories. In a view I say @Html.RenderPartial("[partial view name]"); how does RenderPartial figure out where to look? It must be a convention but what is it?

我的看法是:的WebRoot \\视图\\管理\\ 文件夹和部分在的WebRoot \\视图\\管理\\局部模板

My view is in: WebRoot\Views\Admin\ folder and partial is at WebRoot\Views\Admin\Partials

不知道这是否正确设置。

Not sure if this the right set up.

我使用MVC 3(剃刀引擎)

I'm using MVC 3 (Razor engine)

推荐答案

可以,但你必须注册路线,告诉视图引擎到哪里寻找。例如,在Global.asax.cs中,你将有:

you can, but you have to register the routes, to tell the view engine where to look for. example in Global.asax.cs you'll have:

ViewEngines.Engines.Add(new RDDBViewEngine()); 

和类是:

public class RDDBViewEngine : RazorViewEngine
{
    private static string[] NewPartialViewFormats = new[] {         
        "~/Views/Shared/Partials/{0}.cshtml" ,       
        "~/Views/{0}.cshtml"
    };

    public RDDBViewEngine()
    {
        base.PartialViewLocationFormats = base.PartialViewLocationFormats.Union(NewPartialViewFormats).ToArray();
    }

}

{0} 的是所有与谐音的子文件夹。

{0} is for all the subfolders with partials.

这篇关于的RenderPartial如何找出在哪里可以找到一个看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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