我正在研究和MVC core2项目,它必须替换旧的VB代码。我的问题是来自旧项目的所有链接都应该在新项目中工作。我的模式如下:
routes.MapRoute(
name: "Search",
template : "t/q={keyword}&c={city}&z={zip}&p={page}&dst={district}&sUrl={streetUrl}&cUrl={cityUrl}",
defaults: new { controller = "Search", action = "Index"});
这仅在我填写了所有参数时才有效。有没有什么方法可以让它在没有填充所有参数的情况下工作?
答案 0 :(得分:0)
所以,最后我想出了如何实现这一点。我从模板中删除了查询字符串部分。所以基本上,模板将是
routes.MapRoute(
name: "Search",
template : "t/",
defaults: new { controller = "Search", action = "Index"});
之后,指数行动将是
public IActionResult CompanySearch([FromQuery(Name = "q")] string keyword, [FromQuery(Name = "c")] string city, [FromQuery(Name = "z")] string zip, [FromQuery(Name = "p")] int page, [FromQuery(Name = "dist")] string district, [FromQuery(Name = "sUrl")] string streetUrl, [FromQuery(Name = "cUrl")] string cityUrl)
{
//other stuffs
return View();
}