Question

How to refresh the current page in MVC.

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

I want to refresh my page in else part. That is when return null value.

Était-ce utile?

La solution

You can use Request.UrlReferrer.ToString()

[HttpGet]
public ActionResult Request()
{

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

Autres conseils

You can use the following code in asp.net core

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

Just Redirect to the Action you want to redirect to. It will refresh your page.

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

You can use location.href = location.href; in Javascript code after calling a buttonclick or after a action method call like.

$('#btnme').click(function () {
   location.href = location.href;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top