I have a simple ViewComponent works correctly in the browser chrome and Firefox but 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, F12 Close 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); });
});
Try to set cache false
in ajaxSetup
$.ajaxSetup({ cache: false });
Or use
$.ajax({ cache: false, //other options... });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With