在.net核心中调用两次方法

问题描述 投票:0回答:1

我在启动文件中有这个设置:

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。哪里有问题?

c# asp.net asp.net-core routes
1个回答
0
投票

也许你的id是favicon.ico,所以它null。查找并删除项目中的favicon。我遇到了这个问题,我就这样解决了。

© www.soinside.com 2019 - 2024. All rights reserved.