JINESH
JINESH

Reputation: 1452

Refresh a page in MVC

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.

Upvotes: 21

Views: 109205

Answers (4)

suraj gorad
suraj gorad

Reputation: 51

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;
}

Upvotes: 4

Reza Jenabi
Reza Jenabi

Reputation: 4319

You can use the following code in asp.net core

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

Upvotes: 8

Rahul
Rahul

Reputation: 2307

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");
        }
    }

Upvotes: 6

Jeyhun Rahimov
Jeyhun Rahimov

Reputation: 3787

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());
}

Upvotes: 38

Related Questions