[英]Code throws System.InvalidOperationException
I am trying to submit a form and i run into a 500 internal server error. 我正在尝试提交表单,但遇到500个内部服务器错误。 When i debug the piece of code that is causing this throws an System.InvalidOperationException: 当我调试导致这的代码段时,抛出System.InvalidOperationException:
var description = _context.Malfunction.Single(d => d.Description == newReport.ReportDescsription).ToString();
this is my jquery for the description var: 这是我的描述var的jQuery:
$(document).ready(function () {
vm = {
movieIds: [],
ReportDescription: null
};
function applyChanges() {
vm.ReportDescription = document.getElementById("descriptionReport").value;
if (vm.ReportDescription == "") {
vm.ReportDescription = null;
}
}
ajax post: ajax发布:
$.ajax({
url: "/api/Malfunctions",
method: "post",
data: vm
})
var description = _context.Malfunction.Select(des => desc.Description).FirstOrDefault(d => d.Description == newReport.ReportDescsription);
if(description != null)
{
var str = description.toString();
}
Here you will first verify if the data is returned or is it null, if not null then you can continue with your code. 在这里,您将首先验证数据是否返回或为空,如果不为空,则可以继续执行代码。
Edit: Added Select to only return description, assuming Malfunction has more columns 编辑:添加了选择以仅返回描述,假设故障具有更多列
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.