tags:

views:

34

answers:

2

Hi,

I try using a RedirectToAction after I have done a post to the controller and saved but the url does not chnage and the redirect dsoes not seem to work.....I need to add that the redirect does enter the controller action method when I debug but like I said it does not change the url or navigate to the "Index" view...

public ViewResult Index()
    {
        return View("Index",new TrainingViewModel());
    }

public ActionResult Edit()
{
    //save the details and return to list
    return RedirectToAction("Index");

}

what am I doing wrong ?

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{resource}.js/{*pathInfo}");

            routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = "" } // Parameter defaults
                );
        }

//JQUERY CALLS

this.SynchValuesToReadOnly = function() {
        window.location = $('#siteRoot').attr('href') + 'Sites/';

    };

    this.OnSiteEdit = function() {

        //post back to the server and update the assessment details    
        var options = {
            target: '',
            type: 'post',
            url: '/Site/Edit',
            beforeSubmit: othis.validate,
            success: othis.SynchValuesToReadOnly
        };

        $('#uxSiteForm').ajaxSubmit(options);
                };
+1  A: 

Check with firebug. Post might be returning a server error.

Maxwell Troy Milton King
A: 

The code you show is correct. My wild guess is that you're not doing a standard POST (e.g., redirects don't work with an AJAX post).

The browser will ignore a redirect response to an AJAX POST. It's up to you to redirect in script if you need to redirect when an AJAX call returns a redirect response.

Craig Stuntz