如何使用jQuery刷新ASP.NET MVC UserControl?

时间:2022-12-02 10:27:38

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

我有一个直接绑定到数据库的UserControl,也就是说,它不会由任何Action呈现。它独立工作。

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.

但是,有时候我必须刷新它才能从数据库中获取新信息。我已经通过Ajax在jQuery中刷新了UserControls,但在所有这些情况下,我都有一个Action来创建服务。

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

但是,这次我没有动作,因为UC直接获取其信息。

Does anyone know how to do this?

有谁知道如何做到这一点?

Thanks a lot!!

非常感谢!!

1 个解决方案

#1


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.

然后使用jQuery的load函数刷新控件容器的内部HTML。

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

#1


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.

然后使用jQuery的load函数刷新控件容器的内部HTML。

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