【发布时间】:2017-06-01 15:00:06
【问题描述】:
我在启动文件中有这个设置:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "register",
template: "Register/",
defaults: new { controller = "Account", action = "Register" });
routes.MapRoute(
name: "login",
template: "Login/",
defaults: new { controller = "Account", action = "Login" });
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
ClientsController 中的这个函数:
[HttpGet]
public IActionResult Edit(long? id)
{
var model = _clientsService.GetClientViewModel(id);
return View(model);
}
当我尝试打电话给http://localhost:59824/Clients/Edit/25
此查询调用Edit 函数两次。但在第一次通话id = 5 和第二次通话id = null。
问题出在哪里?
【问题讨论】:
-
我使用该路由和该控制器在本地创建了一个新应用程序,它被调用了一次。也许您正在从视图中获得重定向?
-
当我尝试调用 localhost:59824/Clients/Edit?id=25 时,它只调用一次。
-
出于某种原因,它尝试调用 favicon.ico 查询 imgur.com/a/8I2A5
-
从路由中移除可以为空的 long。你为什么要在里面放一个空值? Chrome(和其他人)会自动请求网站图标,而您正在指定一个默认路由,该路由将多余地分配和匹配 id=null。
标签: c# asp.net asp.net-core routes