简体   繁体   English

ASP.NET MVC RedirectToAction不刷新页面

[英]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. 但是当我通过RedirectoAction方法调用该动作时,出现了问题,页面尚未更新。 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. 该调用我的ResetItems操作,然后将其重定向到Refresh操作。

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? 我还要提及的是,在该项目中,我们使用IUnitOfWork模式可以以某种方式导致这种意外结果吗?

PS i am newbie in ASP.NET please do not judge tough PS我是ASP.NET的新手,请不要强求

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. 我通过提琴手检查我是否从浏览器缓存了结果,或者我猜浏览器没有缓存问题,因为我得到的结果是http 200。

I used this attribute in both actions [OutputCache(Location=System.Web.UI.OutputCacheLocation.None)] Does not help. 我在两个操作中都使用了此属性。 [OutputCache(Location=System.Web.UI.OutputCacheLocation.None)]没有帮助。

You're using AJAX request and it means that regardless of the response the html page will not be reloaded. 您正在使用AJAX请求,这意味着无论响应如何,都不会重新加载html页面。 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);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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