RedirectToAction被忽略 [英] RedirectToAction gets ignored

查看:72
本文介绍了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");
}

我跑步时

http://localhost:59693/MyArea/MyController/DoSomething

通过索引中的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.

并显示在浏览器中

http://localhost:59693/MyArea/MyController/DoSomething

黑屏.

当然,如果您有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");

它仍然显示

http://localhost:59693/MyArea/MyController/DoSomething

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.

这篇关于RedirectToAction被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆