Partial View won't Render List from Database

I have been battling this all day.  Thanks to JohnLocke that I have gotten this far.  I am rendering a Partial View with the Following:

        @Html.Action("GetComments", "LoanApplication")

The partial looks like this:

  @model Portal.ViewModel.Comments.LoanApplicationCommentsViewModel


  @foreach(var item in Model.Comments)
            {
                @item.Comment
            }

The Controller Action looks like this:

[HttpGet]
        [Route("GetComments")]
        public async Task<ActionResult> GetComments()
        {
            var loanApplicationServiceProxy = base.ServiceProvider.LoanApplicationServiceProxy;

            var comments = await loanApplicationServiceProxy.GetLoanApplicationCommentsByLoanApplicationIdAsync(loanApplicationId) ?? new List<LoanApplicationComment>();
            
            var commentsList = new LoanApplicationCommentsViewModel()
            {
                Comments = comments                }
            };
    return PartialView("_CommentsView", commentsList);

Here’s the problem…although the "list" is not empty when the Partial View tries to render it throws an error.  However, if I use the EXACT same code in a Main view, the list is displayed.  The other twist is that if I change the above code to "hardcode"
a comment (like the example below), the Partial displays fine.  What am I missing here?  I’m pulling my hair out.  ANY and ALL assistance is appreciated!

The code below works for the partial (the only difference is that the list is hardcoded).

            var commentsList = new LoanApplicationCommentsViewModel()
            {
                Comments = new List<LoanApplicationComment>{
                    new LoanApplicationComment{
                        Id = Guid.NewGuid(),
                        Comment = "This is a Test Comment",
                        CreatedBy = Guid.NewGuid(),
                        CreatedDate = DateTime.Now,
                        LoanApplicationId = loanApplicationId
                    }
                }
            };
    
            return PartialView("_CommentsView", commentsList);

what is the variable "loanApplicationId" in this line?

var comments = await loanApplicationServiceProxy.GetLoanApplicationCommentsByLoanApplicationIdAsync(loanApplicationId) ?? new List<LoanApplicationComment>();

Its a Guid.  I have it hardcoded in at the top with private readonly Guid loanApplicationId = new Guid("blah-blah-blah").  It’s a real Guid pointing to a real record.  I did figure out that it does NOT like the await, but everything in the project (which
I didn’t create) is all asynchronous calls.  Even if a hardcode the "new" comment, if I don’t comment out the above line, the @Html.Action on the Partial throws an error.

Leave a Reply