您可以使用 jquery ajax 来调用异步操作方法(函数)。数据以 Json 的形式返回。您可以编写代码来反序列化数据并使用 jquery 显示它。
创建一个 Action 方法,它将 JsonResult 作为 viewresult 返回为
public JsonResult GetJsonData()
{
return Json(new
{ testDataResult =TestDataResultObj.Data
JsonRequestBehavior
}, JsonRequestBehavior.AllowGet);
}
并编写以下 jquery 代码:-
if (GetDataAsyc()) {
$.ajax({
type: "GET",
data: { testData: testDataResult },
url: url,// url of action method to be called asynch
dataType: "json",
cache: false,
traditional: true,
contentType: "application/json",
success: function (data) {
// on success assign testDataResult to messages //line
$("#MessagesLines").html(testDataResult .Html);
}
},
error: function () {
//Display error message
$("ErrorMsg").html("There was error whey trying to process your request")
}
});
}