Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Rendering ViewComponent with ajax don't work in Edge/IE11 - ASP.NET Core

$
0
0

I have a simple ViewComponent works correctly in the browser chrome and Firefoxbut do not work in a browser Edge \ IE 11.

The component shows the time (just for example).

Chrome and firefox time is displayed.
 
Edge Browser \ IE 11, time is displayed only the first time the page is up and remains so, time is "frozen".

but

When I open the browser Edge development tools as well as in IE 11, the component starts to work properly and current time is displayed (just like other browsers)

And when I close the F12 development tools, component stops working (time "frozen").


And it repeated - F12 open the component works, F12Close component stops working.

Am I missing something here ?

Attaching the simple code of the process

Thank you

---------------

HomeController

public IActionResult GetTime()
{
   return ViewComponent("GetTime");
   //// var time = DateTime.Now.ToString("h:mm:ss");
  //// return Content($"The current time is {time}");
}

GetTimeViewComponent

public class GetTimeViewComponent : ViewComponent
{

  public IViewComponentResult Invoke()
  {

   var model = new string[]
   {
     "Hello", DateTime.Now.ToString("h:mm:ss") , "the", "view", "component."
   };
   return View("Default", model);

  }

}

Default

@model string[]
<ul>
     @foreach (var item in Model)
     {
       <li class="text-danger">@item</li>
      }
</ul>

Index

<div id="myComponentContainer">@await Component.InvokeAsync("GetTime") </div>

Js / Ajax

$(function () {

   var refreshComponent = function () {
   $.get("Home/GetTime", function (data) {
   $("#myComponentContainer").html(data);
   });
};
   $(function () { window.setInterval(refreshComponent, 1000); });

});


Viewing all articles
Browse latest Browse all 9386

Trending Articles