zoukankan      html  css  js  c++  java
  • Request.UrlReferrer 实现页面刷新

    在使用Ajax 异步提交表单的时候,需要返回某些状态信息。但如果把需要返回的如分页、过滤的参数写在控制器的参数里面,会比较繁琐。

    因此,1、可以在控制器里面使用 Request 对象的请求的URL. Request.UrlReferer.


    //管理员将单个申报项目设置为提交。
    [Authorize(Roles = "SuperAdministrator")]
    [HttpPost]
    public ActionResult MakeASubmit(string id)
    {
    var applicationProject = db.ApplicationProjects.Find(id);
    if (applicationProject == null)
    {
    return new HttpNotFoundResult();
    }
    applicationProject.IsSubmit = true;
    db.SaveChanges();

    if (Request.UrlReferrer != null)
    {
    var returnUrl = Request.UrlReferrer.ToString();
    return new RedirectResult(returnUrl); //返回当前请求的URL。
    }

    return RedirectToAction("Index", "ApplicationProject");
    }

    2、同样,也可以View 中使用。

    如:

    @if (Request.UrlReferrer != null)
    {
    var returnUrl = Request.UrlReferrer.ToString();
    <a href="@returnUrl">返回我的申报列表</a>
    }
    else
    {
    @Html.ActionLink("返回我的申报列表", "IndexForApplicator")
    }

    在javascript 中, 也可以使用  location.href =location.href 刷新页面。这种适用于以Ajax 方式提交表单的情况,因为实践证明,ajax 方式提交的表单使用上述方法,不能更新页面状态。只能原样加退。使用  location.href =location.href 刷新页面能够使用页面状态更新与数据库一样。

  • 相关阅读:
    Good Bye 2015 D
    Good Bye 2015 C
    good bye 2015 B
    寒假训练第九场 Brocard Point of a Triangle
    HDU 3289 Cat VS Dog (二分匹配 求 最大独立集)
    HDU 1029 Ignatius and the Princess IV DP
    找钱问题
    POJ3260——背包DP(多重)——The Fewest Coins
    Charm Bracelet
    POJ1787——背包DP(特定状态+回溯)——Charlie's Change
  • 原文地址:https://www.cnblogs.com/liuyuanhao/p/5616034.html
Copyright © 2011-2022 走看看