Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
MVC6 EF7 Viewcomponent ajax refresh issues

In reference to Viewcomponent alternative for ajax refresh. I can't get the ajax to refresh in MVC6. The JavaScript container finds the Div value but the data is not updating. Any ideas would be appreciated!

ViewComponent - Default.cshtml:

@model IEnumerable<My.Models.Queue>
@foreach (var item in Model)
{
  @item.Queue
}

Index.cshtml:

<div id="Queue" class="blink">@Component.Invoke("Queue")</div>

javascript:

var container = document.getElementById("Queue");
var refreshComponent = function () {
$.get("Shared/Components/Queue", function (data) { container[data]; });};
$(function () { window.setInterval(refreshComponent, 1000); });
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can't make Ajax request directly to the ViewComponent, but you can invoke it from any Controller's method like it's described in post that you mentioned in your question.

So you should create a simple Controller's method like:

public IActionResult QueueViewComponent()
{
    return ViewComponent("QueueViewComponent");
}

And call it from your JavaScript:

var container = $("#queueComponentContainer");
var refreshComponent = function () {
    $.get("/Home/QueueViewComponent", function (data) { container.html(data); });
};

$(function () { window.setInterval(refreshComponent, 1000); });

Where the Home is a Controller's name of your newly created method.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!