I must be stupid to not be able to follow simple destructions or something...but then again I have found often the destructions assume knowledge from previous tutorials and examples from x years ago, that I may not have found.
This seems deceptively simple, but I am obviously missing something.
Never tried working with a partial view before.
I have set up a partial view with the following controller returning the correct records:
Tested it and it works great.
Now I want to merge it into my Site Details view.
In Site.Details I have added the following code to include the partial view and pass in the siteID from the details view (I think).
Which from all the reading I have done follows:
However I am obviously missing something despite studying three different tutorials and msdn.
I am getting an error on loading the details page of:
I cant see from the reading what is wrong?
I don't fully understand why if I manually enter the address as, http://localhost:62233/Jobs/_partialJobHistory/36 it works exactly as desired. So isn't this what I am passing to the partial view in the code? Why isn't it?
This seems deceptively simple, but I am obviously missing something.
Never tried working with a partial view before.
I have set up a partial view with the following controller returning the correct records:
C#:
[COLOR=blue]public[/COLOR] [COLOR=#2b91af]IActionResult[/COLOR] _partialJobHistory(
[COLOR=blue]int[/COLOR] id)
{
[COLOR=blue]var[/COLOR] jobs = [COLOR=blue]from[/COLOR] j [COLOR=blue]in[/COLOR] _context.Job
.Include(j => j.Site)
.Include(j => j.WaterBody)
.Where(j => j.Site.SiteID == id)
.OrderByDescending(j => j.BookingDate)
.Take(9)
[COLOR=blue]select[/COLOR] j;
[COLOR=blue]return[/COLOR] View(jobs);
}
Tested it and it works great.
Now I want to merge it into my Site Details view.
In Site.Details I have added the following code to include the partial view and pass in the siteID from the details view (I think).
C#:
@Html.Partial([COLOR=#a31515]"~/Views/Jobs/_partialJobHistory.cshtml"[/COLOR], Model.SiteID)
Which from all the reading I have done follows:
MvcHtmlString Html.Partial(string partialViewName,object model) | Renders the partial view content in the referred view. Model parameter passes the model object to the partial view. |
However I am obviously missing something despite studying three different tutorials and msdn.
I am getting an error on loading the details page of:
C#:
InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'System.Int32', but this ViewDataDictionary instance requires a model item of type 'System.Collections.Generic.IEnumerable`1[EVA.Models.Job]'.
I cant see from the reading what is wrong?
I don't fully understand why if I manually enter the address as, http://localhost:62233/Jobs/_partialJobHistory/36 it works exactly as desired. So isn't this what I am passing to the partial view in the code? Why isn't it?