tags:

views:

32

answers:

2

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.

+3  A: 

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");  
    }
Oskar Kjellin
A: 

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");  
    }
Muhammad Adeel Zahid