how we can pass parameter and Area in redirecttoaction
return RedirectToAction("Index","Coupon1",
new {Area = "Admin"},
new {id = currentcoupon.Companyid.id});
return RedirectToAction("Index", new { id = currentcoupon.Companyid.id, Area="Admin" });
I don't have enough reputation to add a comment, or to make a change so I will just add this as an answer. The marked answer does not adequately explain the answer and will confuse some people. It assumes a default home controller since it has not explicitly stated the controller and will not work for all situations when another controller is defined for the area. There are many overloads for the Redirect but the simplest one to achieve the stated goal is of the form:
return RedirectToAction("Action", "Controller", new { id=YourId, Area="AreaName" });
Other answers on this post has rewritten the original code correctly but also did not draw the attention to you needing to specify the controller in most situations.
The anonymous object acts as a bag for the MVC route mapper to map all the route values that you may want to include in your Redirects.
If you need to redirect from an controller registered in an area to an controller without area, you have to set the area value to empty like this:
return RedirectToAction("Welcome", "Home", new { Area="" });
Without Area="" you will not be able to redirect to a different controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With