André Miranda
André Miranda

Reputation: 6588

How can I refresh a ASP.NET MVC UserControl with jQuery?

I have a UserControl that binds directly to database, that is, it's not rendered by any Action. It works independly.

But, from times to times I have to refresh it to get new information from database. I've already worked with refreshing UserControls in jQuery via Ajax, but in all of these cases, I had a Action to make the service.

But, this time I don't have a Action since this UC gets its information directly.

Does anyone know how to do this?

Thanks a lot!!

Upvotes: 4

Views: 2321

Answers (1)

Jose Basilio
Jose Basilio

Reputation: 51488

UPDATE:

You need to call an action that returns the controls view. Example:

public ActionResult GetFooControl()
{
   return View("~/Views/Shared/Foo.ascx");
}

Then use the jQuery's load function to refresh the inner HTML for the control's container.

$('#mycontrolContainer').load('../MyController/GetFooControl');

Upvotes: 3

Related Questions