Reputation: 33
Hi I have two controllers and and two views in my application.
I have a save method in the Subscription Controller. I want to call the Home Controller/ Index View after the save is complete. When I do the following I get the page not found error.
return Redirect("Home/Index");
OR
return View("Home/Index");
Could somebody tell me why is the view not getting called ?
Thanks and regards Ranjit Menon
Upvotes: 0
Views: 1034
Reputation: 687
To add on top of Ehsan's answer, I want to point out how to pass parameters around if you need to do this in the future:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult PaymentBillMe(string pledgeAmt, string month, string radioBtn, string btn)
{
return RedirectToAction("PaymentConfirm", new
{
paymentSelection = radioBtn,
paymentAmt = pledgeAmt,
selectedMonth = month
});
}
[HttpGet]
public ActionResult PaymentConfirm(string paymentSelection, string paymentAmt, string selectedMonth)
{
//Do something with parameters...
return View();
}
Here I am passing the radio button selection, pledge amount, and the selected month to the payment confirm method, doing something with those parameters and then returning that view.
Upvotes: 0
Reputation: 62498
you have to use RedirectToAction
as mostly your action Return type is ActionResult
:
return RedirectToAction("Index","Home");
or if you want to return simply view without action, then:
return View("~/Views/Home/Index.cshtml");
See more details here
The second is not recommended you should use first one to redirect to Home/Index, you should not use Rediect
in asp.net mvc you should use RedirectToAction
Upvotes: 3