返回 MVC3 Area 中的 PartialView 未在区域中搜索

发布于 2024-10-02 04:44:56 字数 1421 浏览 3 评论 0原文

我正在开发一个 ASP.Net MVC 3 RC 项目。我有一个名为“驱动程序”的区域。我在驱动程序区域的控制器中有一个 LoadPartial() 操作,它返回 PartialView(string, object);返回此信息后,我的网页上出现错误,显示“未找到部分视图‘PublicAttendanceCode’”。它搜索了以下位置:

~/Views/AttendanceEvent/PublicAttendanceCode.aspx
~/Views/AttendanceEvent/PublicAttendanceCode.ascx
~/Views/Shared/PublicAttendanceCode.aspx
~/Views/Shared/PublicAttendanceCode.ascx
~/Views/AttendanceEvent/PublicAttendanceCode.cshtml
~/Views/AttendanceEvent/PublicAttendanceCode.vbhtml
~/Views/Shared/PublicAttendanceCode.cshtml
~/Views/Shared/PublicAttendanceCode.vbhtml

为什么不在驱动程序区域中搜索?

我在 Global.asax.cs 中有以下非常基本的路线:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home",
              action = "Index",
              id = UrlParameter.Optional  // Parameter defaults
            }
    );
}

在 DriversAreaRegistration.cs 中

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "Drivers_default",
        "Drivers/{controller}/{action}/{id}",
        new { action = "RequestLeave", id = UrlParameter.Optional }
    );
}

我错过了什么会让它在驱动程序区域中查找部分吗?

I am working on an ASP.Net MVC 3 RC project. I have one area named Drivers. I have a LoadPartial() action in a controller in the Drivers area that returns a PartialView(string, object); When this is returned I get an error on my webpage that says "The partial view 'PublicAttendanceCode' was not found." It searched the following locations:

~/Views/AttendanceEvent/PublicAttendanceCode.aspx
~/Views/AttendanceEvent/PublicAttendanceCode.ascx
~/Views/Shared/PublicAttendanceCode.aspx
~/Views/Shared/PublicAttendanceCode.ascx
~/Views/AttendanceEvent/PublicAttendanceCode.cshtml
~/Views/AttendanceEvent/PublicAttendanceCode.vbhtml
~/Views/Shared/PublicAttendanceCode.cshtml
~/Views/Shared/PublicAttendanceCode.vbhtml

Why is it not searching in the Drivers Area?

I have the following pretty basic routes in Global.asax.cs:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home",
              action = "Index",
              id = UrlParameter.Optional  // Parameter defaults
            }
    );
}

And in DriversAreaRegistration.cs

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "Drivers_default",
        "Drivers/{controller}/{action}/{id}",
        new { action = "RequestLeave", id = UrlParameter.Optional }
    );
}

What am I missing that will make it look in the drivers area for the partial?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

老子叫无熙 2024-10-09 04:44:56

您如何向 PartialView() 方法提供区域名称?我认为您应该将其作为routeValues参数传递到new {area =“Drivers”}中。

How are you providing area name to PartialView() method? I think you should be passing it in new { area = "Drivers" } as routeValues parameter.

柠檬色的秋千 2024-10-09 04:44:56

MVC 视图引擎知道它们应该查看的区域的方式基于用于处理请求的路由

对于您拥有的控制器操作,您确定该请求是由该区域的路由定义处理的,还是该请求可能是由您在 global.asax 中定义的更通用的路由处理的?

The way that the MVC view engines know the area that they should look in is based on the route that was used to process the request.

In the case of the controller action that you have, are you certain that the request was processed by the area's route definition, or is it possible that the request was processed by the more general route that you defined in global.asax?

又爬满兰若 2024-10-09 04:44:56

该方法只有四个重载 PartialView 似乎它们都不接受 routeValues 作为参数。

我这样解决了这个问题:

return PartialView(
    VirtualPathUtility.ToAbsolute("~/Areas/MyArea/Views/Shared/MyView.cshtml"));

它有效,但看起来很丑。

There are only four overloads of the method PartialView and it seems like neither of them accept routeValues as a parameter.

I solved this problem like this:

return PartialView(
    VirtualPathUtility.ToAbsolute("~/Areas/MyArea/Views/Shared/MyView.cshtml"));

It works, but looks ugly.

溺孤伤于心 2024-10-09 04:44:56

这也有效:

return PartialView("~/Areas/Admin/Views/Shared/MyView.cshtml", model);

This works too:

return PartialView("~/Areas/Admin/Views/Shared/MyView.cshtml", model);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文