【发布时间】:2014-02-18 12:14:28
【问题描述】:
我正在发出一个 json 请求,如果请求的结果为真,我希望显示一个特定的 div。
目前我收到以下错误,您能帮我解决一下吗?
Microsoft JScript 运行时错误:对象不支持属性或 方法'val'
p.s:我已经通过控制台检查了 json 是否正确返回“true”并且问题是成功的。
我附上下面的代码。
脚本:
<script type='text/javascript'>
$(document).ready(function () {
$('#ComputerLocation').hide();
$('#typeddl').on('change', function () {
$.ajax({
type: 'POST',
url: '@Url.Action("GetItemTypeForm")',
data: { itemTypeId: $('#typeddl').val() },
success: function (result) {
if (result != null && result.val(this.Value) == 'true') {
$('#ComputerLocation').show();
};
}
});
});
});
</script>
控制器:
[HttpPost]
public JsonResult GetItemTypeForm(int itemTypeId)
{
//pseudo code
var data = from s in db.ItemTypes
where s.ItemTypeId == itemTypeId
select new { Value = s.IsComputer };
return Json(data);
}
【问题讨论】:
-
我认为您错过了拼写 val,请尝试使用 value 代替
标签: c# asp.net ajax asp.net-mvc json