Reputation: 325
I'm working on a ASP.net MVC project in Visual Studio 2017 . I want to redirect to a index action which has a Boolean parameter. calling method is below . Without changing the return type how can i redirect to the index action.
Action which needs to redirect to Index action
public async Task<JsonResult> Create(string name)
{
return Json(result);
}
public IActionResult Index(bool isUpdate)
{
}
Upvotes: 0
Views: 564
Reputation: 45
You cannot redirect to another action Method without changing the return type. In your scenario, you will have to change the return type to "ActionResult" and set your return type in fuction declaration to "IActionResult".
Upvotes: 0
Reputation: 218892
You cannot return a redirect response from your Create
action method without changing the current return type!
Change the return type to ActionResult
and then you can use the RedirectToAction
method to return a RedirectResponse
.
RedirectResult
and JsonResult
, both inherits from ActionResult
class
public async Task<ActionResult> Create(string name)
{
return RedirectToAction("Index", new { isUpdate = true });
}
public IActionResult Index(bool isUpdate)
{
return View();
}
Upvotes: 1