【发布时间】:2011-09-14 02:04:30
【问题描述】:
我有一个对函数的 AJAX 调用:
$('#DeviceType').change(function () {
// when the selection of the device type drop down changes
// get the new value
var devicetype = $(this).val();
$.ajax({
url: '@Url.Action("GetEquipmentCode")',
type: 'POST',
data: { deviceTypeID: devicetype },
success: function (result) {
// when the AJAX succeeds refresh the EquipmentCode text box
$('#EquipmentCode').val(result);
}
});
});
函数是
[HttpPost]
public string GetEquipmentCode(int deviceTypeID)
{
var deviceType = _db.DeviceTypes.Single(d => d.ID == deviceTypeID);
return (deviceType.EquipmentCode != null) ?
deviceType.EquipmentCode.Code :
String.Empty;
}
但是,如果函数返回String.Empty,我在文本框中实际得到的字符串是“[object XMLDocument]”。如何在我的文本框中得到空字符串的结果?
【问题讨论】:
-
AJAX 响应应该是 XML 还是 JSON?这是来自 WCF 还是 MVC ActionMethod?
-
MVC 动作方法。还有 XML 或 JSON - 也许这就是我应该返回的而不是字符串?
标签: javascript jquery asp.net-mvc ajax