我在area里面有两个项目,分别是one two
我现在的想法是: one的默认网页是home controller底下的index,two的也是home controller底下的index
我现在打开网页,比如
http://localhost:14209/One 打开的就是 one的默认网页是home controller底下的index
http://localhost:14209/Two打开的就是 Two的默认网页是home controller底下的index
但是可能是我的路由问题,我不得不这样写
http://localhost:14209/One/Home
或者 http://localhost:14209/Two/Home,虽然这样能搞定,但是没有解决我的实际需求。
必须要加上controller名字。下面是我之前的路由配置,请大家指点一下,应该怎么配置才能达到我的要求,谢谢!using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;namespace AreaTest
{
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 = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "AreaTest.Areas.One.Controllers" }
).DataTokens.Add("Area", "One"); }
}
}
我现在的想法是: one的默认网页是home controller底下的index,two的也是home controller底下的index
我现在打开网页,比如
http://localhost:14209/One 打开的就是 one的默认网页是home controller底下的index
http://localhost:14209/Two打开的就是 Two的默认网页是home controller底下的index
但是可能是我的路由问题,我不得不这样写
http://localhost:14209/One/Home
或者 http://localhost:14209/Two/Home,虽然这样能搞定,但是没有解决我的实际需求。
必须要加上controller名字。下面是我之前的路由配置,请大家指点一下,应该怎么配置才能达到我的要求,谢谢!using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;namespace AreaTest
{
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 = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "AreaTest.Areas.One.Controllers" }
).DataTokens.Add("Area", "One"); }
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货