0

Its my first time making a MVC website, so far so good, everything is smooth but I have one big problem.

I am using Layout with Partials for Header, Navigation, Footer. This is my layout.

<div class="page-wrapper">
    <header class="header">
        <partial name="Partials/_HeaderTopPartial"/>
        <div class="header-middle sticky-header">
            <div class="container">
                <div class="header-left">
                    <ul class="menu sf-arrows">
                        <li class="active">
                            <a asp-area="" asp-controller="Home" asp-action="Index">Home</a>
                        </li>
                        <partial name="Partials/NavigationPartials/_NavigationHeaderLeftCategoryPartial"/>
                        <partial name="Partials/NavigationPartials/_NavigationHeaderLeftProductsPartial"/>
                        <partial name="Partials/NavigationPartials/_NavigationHeaderLeftPagesPartial"/>
                    </ul>
                </div>
                <partial name="Partials/NavigationPartials/_NavigationHeaderCenterPartial"/>
                <div class="header-right">
                    <partial name="Partials/NavigationPartials/_NavigationHeaderRightPartial"/>
                </div><!-- End .header-right -->
            </div><!-- End .container -->
        </div><!-- End .header-middle -->
    </header><!-- End .header -->

I am passing a HomeViewModel Model to by _NavigationHeaderLeftCategoryPartial

@model HomeViewModel
<li>
    <a href="category.html" class="sf-with-ul">Categories</a>
    <div class="megamenu megamenu-fixed-width">
        <div class="row">
            <div class="col-lg-8">
                <div class="row">
                    <div class="col-lg-6">
                        <div class="menu-title">
                            <a href="#">Variations 1<span class="tip tip-new">New!</span></a>
                        </div>
                        <ul>
                            <li>
                                <a href="category-banner-full-width.html">Fullwidth Banner<span class="tip tip-hot">Hot!</span></a>
                            </li>
                            <li>
                                <a href="category-banner-boxed-slider.html">Boxed Slider Banner</a>
                            </li>
                            <li>
                                <a href="category-banner-boxed-image.html">Boxed Image Banner</a>
                            </li>
                            <li>
                                <a href="category-sidebar-left.html">Left Sidebar</a>
                            </li>
                            <li>
                                <a href="category-sidebar-right.html">Right Sidebar</a>
                            </li>
                            <li>
                                <a href="category-flex-grid.html">Product Flex Grid</a>
                            </li>
                            <li>
                                <a href="category-horizontal-filter1.html">Horizontal Filter1</a>
                            </li>
                            <li>
                                <a href="category-horizontal-filter2.html">Horizontal Filter2</a>
                            </li>
                        </ul>
                    </div><!-- End .col-lg-6 -->
                </div><!-- End .row -->
            </div><!-- End .col-lg-8 -->
            <div class="col-lg-4">
                <div class="banner">
                    <a href="#">
                        <img src="~/images/menu-banner-2.jpg" alt="Menu banner">
                    </a>
                </div><!-- End .banner -->
            </div><!-- End .col-lg-4 -->
        </div>
    </div><!-- End .megamenu -->
</li>

Everything works fine, until I click on the Login page, which is a partial located in another partial => _NavigationHeaderLeftPagesPartial

<li>
    <a href="#" class="sf-with-ul">Pages</a>
    <ul>
        <li>
            <a href="cart.html">Shopping Cart</a>
        </li>
        <li>
            <a href="#">Checkout</a>
            <ul>
                <li>
                    <a href="checkout-shipping.html">Checkout Shipping</a>
                </li>
                <li>
                    <a href="checkout-shipping-2.html">Checkout Shipping 2</a>
                </li>
                <li>
                    <a href="checkout-review.html">Checkout Review</a>
                </li>
            </ul>
        </li>
        <li>
            <a href="#">Dashboard</a>
            <ul>
                <li>
                    <a href="dashboard.html">Dashboard</a>
                </li>
                <li>
                    <a href="my-account.html">My Account</a>
                </li>
            </ul>
        </li>
        <li>
            <a asp-area="" asp-controller="Home" asp-action="About">About Us</a>
        </li>
        <li>
            <a href="#">Blog</a>
            <ul>
                <li>
                    <a href="blog.html">Blog</a>
                </li>
                <li>
                    <a href="single.html">Blog Post</a>
                </li>
            </ul>
        </li>
        <li>
            <a asp-area="" asp-controller="Home" asp-action="Contact">Contact Us</a>
        </li>
        <li>
            <partial name="_LoginPartial"/>
        </li>
        <li>
            <a a asp-area="Identity" asp-page="/Account/ForgotPassword">Forgot Password</a>
        </li>
    </ul>
</li>

And lastly, the login partial

@using FashionNova.Common
@using FashionNova.Data.Models
@using Microsoft.AspNetCore.Identity
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager


@if (this.SignInManager.IsSignedIn(this.User))
    {
        <a asp-area="Identity" asp-page="/Account/Logout">Logout</a>
    }
    else
    {
        <a asp-area="Identity" asp-page="/Account/Login">Login</a>
    }

The error I am getting

InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'Fashion.Web.Areas.Identity.Pages.Account.LoginModel', but this ViewDataDictionary instance requires a model item of type 'Fashion.Web.ViewModels.HomeViewModel'.

Please, somebody help me to understand how to set up different models for each different partial without them interfering with one another.

jps
  • 20,041
  • 15
  • 75
  • 79
  • Possible duplicate of [this](https://stackoverflow.com/questions/40373595/the-model-item-passed-into-the-dictionary-is-of-type-but-this-dictionary-requ) and [this](https://stackoverflow.com/questions/51388735/the-model-item-passed-into-the-viewdatadictionary-is-of-type-x-but-this-viewda) – itsMasoud Oct 26 '19 at 13:47

1 Answers1

0

Please make sure that you pass models into your views. Here you can find more examples of that: https://learn.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/partial-tag-helper?view=aspnetcore-3.0

Slava Logos
  • 351
  • 1
  • 3
  • 10