我得到了以下函数
function success(result)
{
$("#Div2").html(result);
reloadDisplayAverage();
}
function reloadDisplayAverage()
{
var tdata = $('#form').serialize();
$.ajax({
type: "POST",
data: {
mCollection: tdata,
},
url: "Search/SearchMenu",
success: function (result) { success(result);
});
function success(result)
{
$("#Div1").html(result);
}
我有我的提交按钮
<div id="Div2">
<input type="submit" />
</div>
然后我有一个空的div
<div id="Div1"> </div>,
当我调试时,我在控制器中得到了正确的结果,现在我不知道该把结果放在视图中;。
在我的控制器中,我正在使用
public ActionResult SearchMenu(SVM svm)
{
var sv = qr.QueryResult(svm);
return view() // If I pass like this, I won't get result back to view
// return View(sv) If I pass like this, it won't be valid model for the view as in view is tightly bounded to SVM
}
开始:
HTML:
<div id="Div1"></div> <!--Your result view goes here!!!-->
<button type="button" id="yourButtonId">Post</button>
JQuery:
$("#yourButtonID").click(function(){
function reloadDisplayAverage() {
var tdata = $('#form').serialize();
$.ajax({
type: "POST",
data: tdata,
url: "Search/SearchMenu",
success: function (result) {
$("#Div1").html(result);
}
});
}
});
希望它能有所帮助;)