I want to call a PartialView from my Index.cshtml which uses different Model that I want to call PartialView.
My Index.cshtml
@model IEnumerable<myappname.Models.Post>
...
@Html.Partial("_Block")
_Block.cshtml
@model myappname.Models.RightBlock
<img src="@Model.blockContent" width="330" />
Controller.cs
...
public PartialViewResult _Block()
{
int id = 2;
RightBlock rb0 = db.RightBlocks.Find(id);
return PartialView(rb0);
}
...
Please ignore the id because I just want to call it statically, not dynamically. When I run the Index Page, I get an error:
The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery`1[myappname.Models.Post]', but this dictionary requires a model item of type 'myappname.Models.RightBlock'.
How can I pass different model to call PartialView? Thank you.