简体   繁体   English

代码抛出System.InvalidOperationException

[英]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.

相关问题 Javascript 返回 System.InvalidOperationException: Unexpected new line Error - Javascript returns System.InvalidOperationException: Unexpected new line Error HttpContext.Request.Form 引发了“System.InvalidOperationException”类型的异常 - 为什么? - HttpContext.Request.Form threw an exception of type 'System.InvalidOperationException' - why? Blazor 服务器端应用程序在重新加载期间抛出“System.InvalidOperationException:此时无法发出 JavaScript 互操作调用。...” - Blazor server side application throwing "System.InvalidOperationException: JavaScript interop calls cannot be issued at this time. ..." during reload 在注释系统中禁用代码 - Disable code in comment system jQuery在Smarty代码上引发未捕获的错误 - jQuery throws uncaught error on smarty code PouchDB createIndex抛出500错误代码 - PouchDB createIndex throws a 500 error code 测试400状态代码axios引发错误 - Testing 400 status code axios throws error 对引发错误的异步代码和同步代码进行基准测试 - Benchmarking asynchronous vs synchronous code that throws an error 代码抛出字符串而不是错误时发出警告 - Warn when code throws a string instead of an error npm run build抛出错误代码ELIFECYCLE - npm run build throws error code ELIFECYCLE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM