Reputation: 2577
I have following code that is accepting a form submission
[ActionName("TestingTemp"), AcceptVerbs(HttpVerbs.Post)]
public ActionResult TestingTemp(FormCollection result)
{
string cat = "";
return View("Try");
}
Now the problem is even though it seems to load "Try" page, things break on the page because it doesn't fire the following code (which does get properly fired if I directly go to Try page).
public ActionResult Try()
{
ViewData["Test"] = DataLayer.Test(0, 10);
return View();
}
Also the url contains TestingTemp where it should contain Try, if you know what I mean.
Upvotes: 0
Views: 333
Reputation: 17784
the preferred way is to use redirectToAction but if u do want to go that way then u have to put the required data that u r doing in Try method like
[ActionName("TestingTemp"), AcceptVerbs(HttpVerbs.Post)]
public ActionResult TestingTemp(FormCollection result)
{
string cat = "";
ViewData["Test"] = DataLayer.Test(0, 10);
return View("Try");
}
but as i said this way is not preferred i.e repeating ur code in each action rather u can just write something like
[ActionName("TestingTemp"), AcceptVerbs(HttpVerbs.Post)]
public ActionResult TestingTemp(FormCollection result)
{
string cat = "";
return RedirectToAction("Try");
}
Upvotes: 0
Reputation: 21860
I think what you are looking for is RedirectToAction
. It will redirect to your other method and rewrite the URL.
[ActionName("TestingTemp"), AcceptVerbs(HttpVerbs.Post)]
public ActionResult TestingTemp(FormCollection result)
{
string cat = "";
return RedirectToAction("Try");
}
Upvotes: 3