简体   繁体   中英

ASP.NET MVC RedirectToAction does not refresh the page

I have controller action Refresh which just updates the current page. But when i call that action through RedirectoAction method, i got the problem, page has not updated. I must after that pres refresh button to call independently Refresh action, to got desired result.

This is my client side code. Which call my ResetItems action which in turn redirects to Refresh action.

function ResetSelectedItems() {

var guidId = $("#guidId")[0].value;
console.log(guidId[0].value);
$.ajax({
    type: 'POST',
    url: '/UploadFile/ResetItems',
    data: { guidId : guidId},

     }
)

}

    [HttpPost]
    [ActionName("ResetItems")]
    public ActionResult ResetItems(string guidId) 
    {
      //Some logic here updating in db etc..
      return RedirectToAction("Refresh");
    }

    [ActionName("Refresh")]
    public ActionResult Refresh(int? id) 
    {
      //Refresh logic which eventually render refresh the current view 
    }

Also i would like to mention that in this project we used IUnitOfWork pattern could it lead somehow this kind of unexpected result?

PS i am newbie in ASP.NET please do not judge tough

Edit: What i have done so far to find out what is going on.

I check through fiddler whether i got cached result from browser or and i guess there is no cache problem with browser because i got as a result http 200.

I used this attribute in both actions [OutputCache(Location=System.Web.UI.OutputCacheLocation.None)] Does not help.

You're using AJAX request and it means that regardless of the response the html page will not be reloaded. I guess you need something like this:

[HttpPost]
[ActionName("ResetItems")]
public ActionResult ResetItems(string guidId) 
{
     //Some logic here updating in db etc..
     //string redirectUrl = Url.Action("Refresh", new { id = "your int id" });
     string redirectUrl = Url.Action("Refresh");
     return Json(new { redirectUrl });
}

$.ajax({
    type: 'POST',
    url: '/UploadFile/ResetItems',
    data: { guidId : guidId},
    success: function (response) {
        window.location.replace(response.redirectUrl);
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM