我有我的家庭控制器这样设置,进入不同的功能,取决于它收到的参数。
问题是在我的家庭控制器,它把“游戏二”作为我的路线在我的家庭控制器查询。
示例
the /serchsomething <--这将搜索给定的字符串
This / gametwo <--这也是搜索,而不是去玩两个控制器
我有普通的routeconfig.cs文件,只是添加了属性。
处理多参数路由的最佳方法是什么?这样他们就不会与其他路线发生冲突或坠毁?谢谢
家庭控制器
public ActionResult Index()
{
...
}
[HttpGet]
[Route("{Query}")]
public ActionResult Index(string Query)
{
...
}
[HttpGet]
[Route("{Query}/{Version}")]
public ActionResult Index(string Query, int Version)
{
...
}
GameTwo控制器
[Route("GameTwo")]
public ActionResult Index()
{
return View();
}
routeconfig
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new {
controller = "Home",
action = "Index",
id = UrlParameter.Optional }
);
}
发布于 2016-05-02 11:05:32
试试上面的这个
家庭控制器
[HttpGet]
public ActionResult serchsomething(string Query)
{
//do something
}
游戏2控制器
public ActionResult Index()
{
return View();
}
路由
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
/*serchsomething action*/
routes.MapRoute(
name: "Your route name 1",
url: "serchsomething/{Query}",
defaults: new
{
controller = "home",
action = "serchsomething"
}
);
/*GameTwo Controller*/
routes.MapRoute(
name: "Your route name 2",
url: "GameTwo",
defaults: new
{
controller = "GameTwo",
action = "Index"
}
);
/* default*/
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}}
发布于 2016-05-02 10:52:05
你给出了正确的控制器名称吗?我只是把你的网址
mysite.com/gametwo
but controller name as GameTwo Pls change it as GameTwo and try again.
https://stackoverflow.com/questions/36973887
复制相似问题