刷新MVC中的页面

时间:2014-03-19 05:19:22

标签: asp.net-mvc refresh

如何在MVC中刷新当前页面。

[HttpGet]
public ActionResult Request()
{
    if (Session["type"] != null  && Session["resulttype"] != null)
    {
        return View();
    }
    else
    {
        return null;
    }
}

我想在其他部分刷新我的页面。那就是返回null值。

4 个答案:

答案 0 :(得分:27)

您可以使用Request.UrlReferrer.ToString()

[HttpGet]
public ActionResult Request()
{

    if (Session["type"] != null  && Session["resulttype"] != null)
        return View();
    else
        return Redirect(Request.UrlReferrer.ToString());
}

答案 1 :(得分:5)

只需重定向到您要重定向到的操作即可。它会刷新你的页面。

    [HttpGet]
    public ActionResult Request()
    {
        if (Session["type"] != null  && Session["resulttype"] != null)
        {
            return View();
        }
        else
        {
            return RedirectToAction("Request");
        }
    }

答案 2 :(得分:4)

您可以在asp.net核心中使用以下代码

public IActionResult Index(){
         return Redirect($"{Request.Path.ToString()}{Request.QueryString.Value.ToString()}");
}

答案 3 :(得分:1)

您可以在调用location.href = location.href;之后或类似的操作方法调用之后在Javascript代码中使用buttonclick

$('#btnme').click(function () {
   location.href = location.href;
}