【发布时间】:2015-06-18 12:50:28
【问题描述】:
我正在尝试从如下发送的请求中返回 JSON 格式的模型:
$(document).ready(function() {
(function(){
console.log("ran");
$.ajax({
type: "GET",
url: "https://clas.uconn.edu/Employees/Edit/22",
success: function(data) {
console.log("Success: " + data);
empData = data;
}
});
})();
});
我的这个方法的控制器是:
// GET: Employees/Edit/5
public ActionResult Edit(int? id)
{
var id = employee.id;
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
if (employee == null)
{
return HttpNotFound();
}
return new JsonResult() { Data = employee, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
Console.WriteLine("error");
}
但是,即使这些控制器操作都没有返回视图,我也会在 consol 日志中获得整个 html 页面。有什么想法吗?
编辑: 添加数据类型后,我在控制台日志中收到错误消息:
GET http://localhost:59909/Employees/EmployeeLookupDisplay
net::ERR_CONNECTION_REFUSED
【问题讨论】:
-
你的动作控制器的哪一部分被击中了?据我所知,HttpNotFound() 将返回整个 HTML 页面。
-
你的控制器动作成功了吗?
-
从 MVC 控制器接收到的那个 html 页面上有什么,通常会出现错误,黄屏死机,所以使用 chrome 开发工具或其他工具来呈现该页面(点击预览)