BASEER ULHASSAN
BASEER ULHASSAN

Reputation: 461

Controller not Refreshing from AJAX

I am confused as how to Refresh a controller from my Client. I send a call from my client to hit a ActionMethod in controller which will Refresh my page after 7 sec. The call gets to Controller, Logs are created but Refresh never takes place.

Ajax Call to hit Controller's ActionMehtod and Refresh whole Controller/DOM.

<script>
   $.get("@Url.Action("Refresh","Driver")",function(data){
   $("#View1").html(data);
    });
   alert("Refresher ActionResult Exit");
</script>

Refresh ActionResult Method just calls Refresh after 7 seconds, With no View attached to it:

 public ActionResult Refresh()
    {
        logger.AddLog("PAGE Refresh Set to 7 sec");
        Response.AddHeader("Refresh", "7");
        logger.AddLog("Returning From Refresher Function");
        return View();
    }

Upvotes: 0

Views: 120

Answers (1)

Khyron
Khyron

Reputation: 468

I think you are confusing two different refresh methods.

If you want to update part of a page (#View1) every 7 seconds, the best way is to use javascript in _Layout.cshtml with setInterval(). A refresh header is unnecessary in that situation.

If you want to update the entire page every 7 seconds, use a Response.AddHeader() from your view, or <meta http-equiv="refresh" content="7"> in _Layout.cshtml and then no javascript is necessary.

Upvotes: 1

Related Questions