[英]Ajax Call not returning Partial View
I am making an AJAX
call, and then returning PartialView
from Controller to populate it in a div
. 我正在进行AJAX
调用,然后从Controller返回PartialView
以将其填充到div
。
The following is my code :- 以下是我的代码:-
var file = document.getElementById("file").files[0];
jq.ajax({
type: "POST",
url: '/Main/getData',
data: formData,
dataType: 'json',
contentType: false,
processData: false,
success: function (response) {
jq('#partialPlaceHolder').html(response);
},
error: function (error) {
alert("Some Error Occured");
}
});
[HttpPost]
public ActionResult getData(FormCollection form)
{
......
return PartialView("_pageMain", retMod);
}
As I debug the Code in Controller, there is no Error till the end, But still the AJAX throws the alert("Some Error Occured")
. 当我在Controller中调试代码时,直到最后都没有错误,但是AJAX仍然会alert("Some Error Occured")
。
The PartialView is not populated in div. 未在div中填充PartialView。 How to solve this? 如何解决呢?
You are setting the return data type to json 您正在将返回数据类型设置为json
dataType: 'json'
try changing this to 尝试将其更改为
dataType: 'html'
See here http://api.jquery.com/jquery.ajax/ 看到这里http://api.jquery.com/jquery.ajax/
dataType (default: Intelligent Guess (xml, json, script, or html)) Type: String The type of data that you're expecting back from the server. dataType (默认值:Intelligent Guess(xml,json,脚本或html))类型:String期望从服务器返回的数据类型。
Why not to use .load()
JQuery .load() ? 为什么不使用.load()
JQuery .load() ?
Description: Load data from the server and place the returned HTML into the matched element. 描述:从服务器加载数据并将返回的HTML放入匹配的元素。
And simple: 很简单:
$('#partialPlaceHolder').load("@Url.Action('getData')", { form: formData })
Third parameter for .load()
is callback function, so feels free with it. .load()
第三个参数是回调函数,因此可以.load()
使用。
BTW: I did not find using variable file
in your code. 顺便说一句:我没有在您的代码中找到使用变量file
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.