RedirectToAction is ignored

I am using ASP.NET 5. Using the Chrome browser.

My controller has the following action method

public async Task<IActionResult> Index() { return View(); } [HttpPost] public IActionResult DoSomething() { //do something return RedirectToAction("Index"); } 

When i started

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

through POST in the index

and have a breakpoint on the line

  return RedirectToAction("Index"); 

it simply ignores the line and moves on to the next line without calling the index action method.

and displayed in the browser

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

with a blank screen.

Of course, if you have a return statement, it immediately returns from this method and does not go to the next line. Really odd.

I even tried completely

  return RedirectToAction("Index","MyController,new {area="MyArea"}); 

When I put a breakpoint in my index action method, it never hits.

I even tried

  return Redirect("http://www.google.com"); 

It still displays

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

Some error in ASP.NET 5?

How can I call an action method from an action method in the same controller if the above does not work?

+3
source share
1 answer

I changed the DoSomething action method as asynchronous and added a wait clause

 [HttpPost] public async Task<IActionResult> DoSomething() { await _db.callsql(); //do something start return RedirectToAction("Index"); } 

The problem is that the actionmethod Index was asynchronous, but there is no DoSomething , combined with me by stepping over the code.

+4
source

Source: https://habr.com/ru/post/1261843/


All Articles