1

I am trying to send list received in var result to my view in order to display it. I am able to get values in Controller for var result but when I want to pass those values in order to use in View I am getting error on result.ResponseObject saying System.Collection cant be converted to Base. Basically var result has a list.

But i am getting error.

The model item passed into the ViewDataDictionary is of type 'System.Collections.Generic.List`1[Project.Models.Document]', but this ViewDataDictionary instance requires a model item of type 'Project.Models.Document'.

Controller:

public  async Task<IActionResult> GetAllSavedDocument(int id)
{
    var result = await _applicationService.GetAllSavedDocument(id);

    return HandleResult(() => View("_Alldocuments", result.ResponseObject), result.Status);

}

My model contains information

public class Document
{
  public int ApplicationID { get; set; }
  public string URI { get; set; }
  public string Author { get; set; }
 }
Tina
  • 89
  • 1
  • 11

1 Answers1

2

Your view needs to reference a list not a single object.

change @model Document to @model List<Document> or @model IEnumerable<Document> int the "_Alldocuments" view

Aaron Roberts
  • 1,342
  • 10
  • 21