我有两种方法
[HttpGet]
public ActionResult Edit(int? id)
{
// do stuff
return View();
}
[HttpPost]
public ActionResult Edit(Object object)
{
//do more stuff
return View();
}
我正在尝试测试这个方法,例如我想通过null
到 Controller ,我收到歧义错误。
var controller = new Controller();
controller.Edit(null); // ambiguity error
如何区分我要调用 GET 还是 POST 方法?
最佳答案
您还可以使用参数化调用。
[HttpGet]
public ActionResult Edit(int? id)
{
return View();
}
[HttpPost]
public ActionResult Edit(Object myObject)
{
return View();
}
.
var controller = new Controller();
controller.Edit(myObject: null);
controller.Edit(id: null);
关于c# - 在 ASP.MVC 中测试具有相同名称的 Controller 中的 GET/POST 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43010432/