加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net mvc 3区域和url路由配置

发布时间:2020-12-16 09:35:34 所属栏目:asp.Net 来源:网络整理
导读:我有为asp.net mvc3应用程序创建ulr路由的问题. 我的项目有这样的结构: 领域 EmployeeReport 控制器 报告 意见 报告 列表 …. 控制器 登录 Viwes 登录 …… EmployeeReportAreaRegistration.cs: public class EmployeeReportAreaRegistration : AreaRegist
我有为asp.net mvc3应用程序创建ulr路由的问题.

我的项目有这样的结构:

>领域

> EmployeeReport

>控制器

>报告

>意见

>报告

>列表
> ….

>控制器

>登录

> Viwes

>登录

> ……

EmployeeReportAreaRegistration.cs:

public class EmployeeReportAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get
        {
            return "EmployeeReport";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        var routes = context.Routes;

        routes.MapRoute(null,"vykazy/vykazy-zamestnance",new { Area = "EmployeeReport",controller = "Report",action = "List" });

    }
}

Global.asax:

routes.MapRoute(null,"prihlasit",new { controller = "Login",action = "Login" });

        routes.MapRoute("Default","{controller}/{action}/{id}",new { controller = "Default",action = "Welcome",id = UrlParameter.Optional });
When i try load "http://localhost/app_name/vykazy/vykazy-zamestnance
i get this exception :

The view 'List' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Report/List.aspx
~/Views/Report/List.ascx
~/Views/Shared/List.aspx
~/Views/Shared/List.ascx
~/Views/Report/List.cshtml
~/Views/Report/List.vbhtml
~/Views/Shared/List.cshtml
~/Views/Shared/List.vbhtml

那么,我错在哪里?

谢谢

解决方法

修改回答:

直接添加到Context.Routes意味着它会丢失有关Area的任何信息.

使用AreaRegistration.MapRoute(覆盖以放入Area信息).

context.MapRoute(...);

或者将该区域放在DataTokens参数中(而不是像在此处所做的默认参数)

context.Routes.MapRoute("","url",new {...},null,new {area = this.AreaName});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读