c# – Asp.net Mvc区域路由问题
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – Asp.net Mvc区域路由问题,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2275字,纯文字阅读大概需要4分钟。
内容图文
![c# – Asp.net Mvc区域路由问题](/upload/InfoBanner/zyjiaocheng/778/d61cabce070748a6abf8ee9b297d48fd.jpg)
我希望网站的默认页面是Login.cshtml.我得到了例外:
Error: The view ‘LogIn’ or its master was not found or no view engine supports the searched locations. The following locations were searched:
我有2个区域.结构如下所示.
我的routeconfig如下所示.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace Portal.Web
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "LogIn", id = UrlParameter.Optional },
namespaces: new[] { "Portal.Web.Areas.Management" }
);
}
}
}
我的global.asax.cs如下所示:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
namespace Portal.Web
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
}
“你有什么建议吗?
解决方法:
你忘了一些东西
概括:
ManagementAreaRegistration.cs
public class ManagementAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Management";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Management_default",
"Management/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"Default" // Route name
, "{controller}/{action}/{id}" // URL with parameters
, new { area = "management", controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
, new[] { "Portal.Web.Areas.Management.Controllers" } // Namespace of controllers in root area
);
}
你设置Portal.Web.Areas.Management它应该是Portal.Web.Areas.Management.Controllers它也缺少默认区域:area =“management”
内容总结
以上是互联网集市为您收集整理的c# – Asp.net Mvc区域路由问题全部内容,希望文章能够帮你解决c# – Asp.net Mvc区域路由问题所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。