0

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.

2 Answers 2

3

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");  
    }
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.