Results 1 to 3 of 3

Thread: Getting a JSonResult to Redirect

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Getting a JSonResult to Redirect

    Hi All,

    In my view I havethe following piece of code:
    Code:
    var jSonData = '{ "available" : "  ' + availableArray +
                    '", "assigned" : " ' + assignedArray +
                        '", "policyZoneID" : " ' + document.getElementById('policyZoneID').value + '"}';
    
                $.ajax({
                    type: 'POST',
                    url: window.rootDir + 'FloatingZone/JsonEditFloatingZone',
                    data: jSonData,
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'json',
                    success: function (response) {
                        window.location.href = response.newLocation;
                    },
                    error:  function (xmlHttpRequest, textStatus, errorThrown) {
                        alert(errorThrown);
                    }
                 });
    and then back in the controller:

    Code:
    public JsonResult JsonEditFloatingZone(string available, string assigned, int policyZoneID)
            {
                string newLocation = string.Concat("../../Edit/", policyZoneID);
    
                string apportionmentLocation = string.Concat("/ParentZoneSectionsApportionment/Edit/", policyZoneID);
    
                if (FloatingZoneService.EditPolicyZoneFloatingZone(available, assigned, policyZoneID, CurrentUser)) 
                    { newLocation = apportionmentLocation; }
     
    
    
               return new JsonResult { Data = new { newLocation } };
    
            }
    Now as it stands this all works fine and the view correctly does to my desired location.

    I've now been asked to remove the hard coded paths since this may not be the eventual path on deployment and that I should use the conventional MVC way of redirecting. This would be fine if I was performing an ActionResult, but I'm performing a JsonResult, so what's the best way to do this without a total re-design?

  2. #2
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: Getting a JSonResult to Redirect

    Couldn't you generate your new location string with Url.Action()? It takes the same arguments as RedirectToAction().
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Re: Getting a JSonResult to Redirect

    Ah, I wasn't aware of that one. Will give it a try.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width