以下网址
http://localhost:53130/Quote/FindCustomer?f=0
给我
The view '0' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Quote/0.aspx ~/Views/Quote/0.ascx ~/Views/Shared/0.aspx ~/Views/Shared/0.ascx ~/Views/Quote/0.cshtml ~/Views/Quote/0.vbhtml ~/Views/Shared/0.cshtml ~/Views/Shared/0.vbhtml
但它可以在没有 f
参数的情况下工作。
操作代码如下所示:
public ActionResult FindCustomer(string f = "")
{
return View(f);
}
我以前也发生过类似的事情,但我一直不明白为什么。
我需要做什么才能让它识别出 f 是一个参数?
[编辑]
正如答案所暗示的那样,我将参数作为 View 名称传递,而不是我想的模型。
以下解决了这个问题:
return View(model: f);
最佳答案
错误的原因是 return View(f);
。当您不为您的方法提供参数时,它有 return View("");
,它似乎默认为与您有 return View();
。然后映射到方法的名称,或 return View("FindCustomer");
。
您显示的错误消息完美地解释了问题。使用您提供的“?f=0”URL,您告诉它查找名为“0.cshtml”的不存在的 View 。
关于c# - 参数未被视为参数 - 可能的路由问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35014495/