微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:无法对空引用执行运行时绑定

如何解决Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:无法对空引用执行运行时绑定

我正在尝试根据下拉列表中的值项目显示编辑卡,但此错误正在显示

无法对空引用执行运行时绑定说明: 当前Web执行期间发生未处理的异常 请求。请查看堆栈跟踪以获取有关 错误及其在代码中的起源。

异常详细信息: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:无法执行 空引用上的运行时绑定

[![在此处输入图片描述] [1]] [1]

这是我的观点

   @if (ViewBag.EnableEditBookRequest != null)
            {
          
                           ...
     <label for="">Request Number</label>
       @Html.TextBoxFor(m => m.bookRequest.RequestNo,new { @Value = ViewBag.Bookrequest.RequestNo,@class = "form-control m-input",@placeholder = "",@readonly = "readonly",@id = "requestNo" })
       @Html.ValidationMessageFor(m => m.bookRequest.RequestNo,"",new { @class = "text-danger" })
                                    ......
     <label for="">Employee Code</label>
    @Html.TextBoxFor(m => m.bookRequest.EmployeeId,new { @Value = ViewBag.Bookrequest.EmployeeId,@id = "employeeId" })
    @Html.ValidationMessageFor(m => m.bookRequest.EmployeeId,new { @class = "text-danger" })
                                    </div>
   
                                
             }

这是ViewBag.EnableEditBookRequest

 public ActionResult AddBookRequest()
    {
        int id = 0;
        if (User.Identity.IsAuthenticated)
        {
            UserInfo = (CustomMembershipUser)Membership.GetUser(HttpContext.User.Identity.Name,false);
            Session["CurrentUser"] = UserInfo.FirstName + " " + UserInfo.MiddleName + " " + UserInfo.LastName;
        }
        BookRequestviewmodel model = new BookRequestviewmodel();
        ViewBag.EnableEditBookRequest = PopulateEnableEditBookRequest(id);
        ViewBag.EditBookRequest = PopulateEnableEditBookRequest(id);            
        return View(model);
    }

这是PopulateEnableEditBookRequest函数

   public JsonResult PopulateEnableEditBookRequest(int? id)
    {
        var listofBooks = new List<BookRequestviewmodel>();
        int OrgId = (Int32)Session["OrgId"];
        int LicId = (Int32)Session["GlobalLicenseId"];
        using (MarketEntities db = new MarketEntities())
        {
             listofBooks = (from br in db.BookRequests
                           join brd in db.BookRequestDetails on br.RequestNo equals brd.RequestNo
                           join t in db.marketingrectypes on brd.ReceiptTypeId equals t.id
                           where br.EmployeeId == id //for test
                           && br.OrgId == OrgId
                           && brd.FinanceApproval == 0 && brd.SupervisorApproval == 0 && t.LicenceId == LicId
                           select new BookRequestviewmodel()
                           {
                               Id = brd.Id,RequestNo = br.RequestNo,EmployeeId = br.EmployeeId,ReceiptTypeId = brd.ReceiptTypeId,bookTypeName = t.name,Amount = brd.Amount,RequestDate = br.RequestDate,SupervisorApproval = brd.SupervisorApproval,FinanceApproval = brd.FinanceApproval
                           }).ToList<BookRequestviewmodel>();
        }

        return Json(listofBooks,JsonRequestBehavior.AllowGet);
    }

此Java脚本功能

$("#empList").change(function () {
        var data = [];
        var selectedvalue = $("#empList option:selected").val();
        $.ajax({
            type: 'GET',url: '/BookRequests/PopulateEnableEditBookRequest?id=' + selectedvalue,dataType: 'json',success: function (data) {
                alert('successful');
                $('#requestNo').val(data[0].RequestNo);
                $('#employeeId').val(data);
                $('#RequestDate').val(data);

            },error: function () {
                console.log('sorryyyyy sorryyyyy');
                //Console.error()

            }
        });
    });

谁能帮助我:(? [1]:https://i.stack.imgur.com/wo0LI.jpg

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。