0

I have been searching for a solution this problem for quite some time, including browsing the message board here. To start off, I will refer to an existing post:

I have used the most popular solution, and the controller successfully runs the query:

 [HttpGet]
 public ActionResult LoadBidders(int Id)
 {
      List<tblWinLossBidderMap> bidders = _context.tblWinLossBidderMaps.Where(p => p.WinLossID == Id).ToList();
      return PartialView("_WinLossBidderView", bidders);
 }

The Javascript

$(document).ready(function () {
$("#pY").on("click", function () {
    var temp = $("#WinLossID").val();
    $.ajax({
            url: "/WinLoss/LoadBidders",
            type: "GET",
            data: { Id: temp }
        })
        .done(function(partialViewResult) {

            $("#BidderCompany").html(partialViewResult);
        });
   });
});

The problem I have is that when the controller exits, back into the Javascript, I get an exception "Microsoft.CSharp.RuntimeBinder.RuntimeBinderException", "Cannot convert null to 'bool' because it is a non-nullable type value".

Note that the partial view uses a foreach to display the data. Ideally, once this is working, I will take the code snippet and append it after another jquery function that actually adds to this list. The effect is the user would fill in part of a larger form (like master/detail), click a button, a record would be added, and then this routine would update the partial view with the updated information. I doubt this part is important, but just including it for completeness.

Is there some something missing from my code?

Note that I am using Visual Studio 2015.

Community
  • 1
  • 1
  • 1
    The exception is most likely related to the code in your partial view (you need to show it) –  Feb 23 '17 at 00:50
  • As a side note, you may run into caching issues (stale data returned) using a GET request instead of a POST, either on the browser's side, or via the server's output cache, or both. – plushpuffin Feb 23 '17 at 01:05
  • Sounds like a NULL value from the database is trying to get put into a bool property, which could be with your entities (code first?) – Brian Mains Feb 23 '17 at 01:42
  • If the exception is thrown after the controller's action execution, then the exception is probably being caused by something in your partial view. please update the question with the code of the partial view. – Miguel Ramirez Feb 23 '17 at 02:21
  • Thanks for all the comments. Yes, the answer was in the view, in that I accessed the Viewbag (I had a flag there to determine if a form field was read-only) and that was null. It worked fine from the main view, but not from the reloading in the action. In addition, yes, I had caching issues from the GET and I redid it as a POST, and I am now returning the correct HTML (I did an alert on the result, which shows correctly), but somehow it isn't correctly inserting into the DIV:
    . I will work on that more.
    – Edwin Rooks Feb 23 '17 at 15:48

0 Answers0