我在启动文件中有这个设置:
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
。哪里有问题?
也许你的id
是favicon.ico,所以它null
。查找并删除项目中的favicon。我遇到了这个问题,我就这样解决了。