At the top of your view file, you have something like:
@model MyViewModel
<div class="border">
<h2>@Model.PageName</h2>
<p>@Model.TeaserText</p>
<p>
...
</p>
</div>
Do you pass in a model that matches the @model directive?
hi, yes, i pass the correct model, and when i debug the view i even get the data correctly, but then i have an error that the view expecting other model
but if i write in the view "@layout = null", then i see the view and everything is ok - but i dont have the layout, which i need
Generally, the layout page is based on a model e.g. in Alloy layout is based on @model IPageViewModel<SitePageData> and this model has many properties depending on Page Data. Not sure using the same layout page could be the best approach.
Creating anew layout page for your views (views for those pages, not EPi Pages) could be an idea where you could define some strategy to select correct layout page or defining a layout in your view could also work. e.g.
rather
@layout = null
use something like
@{
Layout = "~/Views/Shared/NoIContent.cshtml";
}
If you want to show both Episerver and non episerver content, it might be better to create two layout pages.
In _viewstart.chstml
you can have something like this:
@{
Layout = ViewContext.ViewBag.LayoutPage;
}
And then in PageContextActionFilter.OnResultExecuting
you can set the layout like this:
var viewModel = filterContext.Controller.ViewData.Model;
// epi
if (viewModel is IPageViewModel<...>)
{
filterContext.Controller.ViewBag.LayoutPage = "~/Somepath/Layout.cshtml";
}
else
{
...
}
Hi, I start building a site with MVC and epiServer cms, creating layout and homepage according to epiServer documantation and everything worked fine.
Now i want to add a page, which is not a contentType page (i dont extract data from the cms) but still use the layout i created.
I changed the route by attribute and managed to get to the controller, passing my own model.
The problem is i got an error: the view expect to get other model.
What should i do?
Thank you,
dovrat