asp.net mvc的jQuery的 - 显示部分页面返回结果?页面、部分、结果、net

2023-09-11 01:36:11 作者:云朵很甜

使用jQuery的,是它可以调用 / ControllerName / GetSomething?参数=测试,而在 GetSomething 方法我有以下:

With jQuery, is it possible to call /ControllerName/GetSomething?parameter=test, while in GetSomething method I have following:

public ActionResult Details()
{
    filterQuery.OrderBy = Request.QueryString["parameter"];

    var contacts = contactRepository.FindAllContacts(filterQuery).ToList();

    return View("ContactList");
}

然后ContactList.ascx的淡出当前的显示与更新某一替代它?

and then fadeOut current display of ContactList.ascx replacing it with updated one?

推荐答案

有一个PartialViewResult返回类型:

There is a PartialViewResult return type:

public PartialViewResult Details()

然后返回PartialView

Then return a PartialView

return PartialView("ContactList");

在jQuery的,使用load()方法来检索使用AJAX的结果,然后使用jQuery的淡入(),淡出(),和fadeTo的某种组合()方法。

In jQuery, use the load() method to retrieve the results using AJAX and then use some combination of the jQuery fadeIn(), fadeOut(), and fadeTo() methods.

$('#result').load('/ControllerName/GetSomething?parameter=test', function() {
  $('#result').fadeOut etc...
});