I use asp.net core 2 new feature Razor pages. in the _layout.cshtml.
<body>
<div>
@await Html.PartialAsync("_LayoutHeader")
<div class="row">
<div>
<div class="row">
@RenderBody()
</div>
</div>
</div>
the _layoutHeader.cshtml is page with code behind.
@page
@using Microsoft.AspNetCore.Identity
@model Yiko.Ent.WebRazorPages.Pages._LayoutHeaderModel
and @RenderBody will load index.cshtml with pagemodel.
@page
@model Yiko.Ent.WebRazorPages.Pages.Home.IndexModel
@{
ViewData["Title"] = "Home";
}
run the project. throw a error:
InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'Yiko.Ent.WebRazorPages.Pages.Home.IndexModel', but this ViewDataDictionary instance requires a model item of type 'Yiko.Ent.WebRazorPages.Pages._LayoutHeaderModel'. Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.EnsureCompatible(object value)
@Html.PartialAsync("_LayoutHeader", {your model})
– Svek