I have Partial view LeftBanner.cshtml that should display some data from DB (images)
LeftBanner.cshtml
@model IEnumerable<WebApplication1.ViewModels.Banner>
<table class="table">
<tr>
<th>Test Banner!</th>
</tr>
@foreach (var banner in Model)
{
<tr>
<td>
@Html.LabelFor(b => banner.ImageDesc);
<img src="@Url.Content(banner.ImagePath)" alt="Image" />
</td>
</tr>
}
</table>
SharedController
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication1.ViewModels;
namespace WebApplication1.Controllers
{
public class SharedController : Controller
{
public ActionResult LeftBanner()
{
List<Banner> b = new List<Banner>() {
new Banner() {ImageDesc = "Left Banner Description", ImagePath = "~/Images/money.jpg" },
new Banner() {ImageDesc = "Left Banner Description2", ImagePath = "~/Images/money.jpg" }
};
return View(b);
// return View();
}
}
}
_Layout.cshtml
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
@RenderPage("~/Views/Shared/LeftBanner.cshtml")
</div>
</body>
</html>
The Error
The model item passed into the dictionary is of type 'WebApplication1.ViewModels.EmployeeListViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[WebApplication1.ViewModels.Banner]'.
In Asp.net Web-forms ascx UserControls can be independent and really reusable.
Please help my to understand, why i can't encapsulate my partial view? It is not real reuse, If I have to pass to partial view model every time I use it. Can it be independent and go to a database without passing it a model?
Thanks a lot!