I am trying to overload an MVC Action, but since “overloading” does not work for route actions (error 500 says ambiguous method I guess because parameters cannot be strongly typed from the browser), then I thought I would just return one action to another since I cannot use RedirectToAction for HttpPost either. The issue is that it is trying to find a view with the new action name instead of what aciton I am trying to call. Here is what I am trying to do:
[HttpPost]
public ActionResult DetailForProductID(int productID)
{
return Detail(new[] { GetProductById(productID) });
}
[HttpPost]
public ActionResult Detail(IEnumerable<Product> products)
{
....
return View(productViewModel);
}
This is the error I get though:
The view 'DetailForProductID' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Products/DetailForProductID.aspx
~/Views/Products/DetailForProductID.ascx
~/Views/Shared/DetailForProductID.aspx
~/Views/Shared/DetailForProductID.ascx
~/Views/Products/DetailForProductID.cshtml
~/Views/Products/DetailForProductID.vbhtml
~/Views/Shared/DetailForProductID.cshtml
~/Views/Shared/DetailForProductID.vbhtml
What is the most robust and elegant way to handle this? I would not want to store things in temporary sessions or do a RedirectToAction becase I should be able to do everything server-side. Any help or advice would be greatly appreciated.
You can also use Tempdata in this scenario, for example: