RedirectToAction被忽略
我正在使用ASP.NET5.使用浏览器Chrome.
I am using ASP.NET 5. Using the browser Chrome.
我的控制器具有以下操作方法
My Controller has the following Action Method
public async Task<IActionResult> Index()
{
return View();
}
[HttpPost]
public IActionResult DoSomething()
{
//do something
return RedirectToAction("Index");
}
我跑步时
通过索引中的POST
via a POST in Index
并在该行上有一个断点
return RedirectToAction("Index");
它只是忽略该行,而转到下一行而不调用Index action方法.
it just ignores the line and goes to the next line without calling the Index action method.
并显示在浏览器中
黑屏.
当然,如果您有return语句,那么它会立即从该方法返回,并且不会跳转到下一行.真的很奇怪.
Surely if you have a return statement then it immediately returns from that method and doesn't jump to the next line. Really odd.
我什至尽力了
return RedirectToAction("Index","MyController,new {area="MyArea"});
当我在索引操作方法上设置断点时,它永远不会受到攻击.
When I put a breakpoint on my Index Action Method it never gets hit.
我什至尝试
return Redirect("http://www.google.com");
它仍然显示
ASP.NET 5中的一些错误?
Some bug in ASP.NET 5?
如果上述方法不起作用,如何从同一控制器中的动作方法调用动作方法?
How to I call an action method from an action method in the same controller if the above doesn't work?
我将DoSomething操作方法更改为异步,并添加了一个await子句
I changed my DoSomething action method to be asynchronous and added an await clause
[HttpPost]
public async Task<IActionResult> DoSomething()
{
await _db.callsql();
//do something start
return RedirectToAction("Index");
}
问题似乎是因为动作方法Index
是异步的,但DoSomething
不是异步的,与我逐步执行代码结合在一起.
The issue seems to be because the actionmethod Index
was asynchronous but DoSomething
not, combined with me stepping through the code.