【发布时间】:2010-11-24 09:08:23
【问题描述】:
我试图在我的 .net mvc 应用程序中通过 jquery 的 ajax 方法提交表单。我已将 dataType 设置为 json 并将 contentType 设置为“application/json; charset=utf-8”。在我的控制器操作中,我返回一个 JsonResult。
由于某种原因,JSON 响应没有得到正确处理,而是出现一个对话框来保存其中包含 JSON 对象的文件。
$(document).ready(function() {
$("#editPageContentForm").submit(function() {
$.ajax(
{
type: "POST",
dataType: "json",
url: $("#editPageContentForm").attr("action"),
contentType: "application/json; charset=utf-8",
data: { ID: $("#id").val(), small_title: $("#small_title").val(), big_title: $("#big_title").val(), body: $("#body").val(), subheading: $("#subheading").val() },
success: function(result) {
alert('hi');
},
error: function(req, status, error) {
alert("Sorry! We could not receive your feedback at this time.");
}
}
);
})
在我的控制器操作中,我有类似的东西:
public JsonResult Edit(int id, string small_title, string big_title, string subheading, string body)
{
return Json(new {success = true, message = "success"});
}
为什么响应没有以 JSON 格式返回?
【问题讨论】:
标签: .net jquery asp.net-mvc model-view-controller json