0

I use asp.net mvc 5. I created popup window in my layout page above render body element:

    <div class="body-content" style="padding-left:15px;padding-right:15px;">
        <!-- Subscribers popup -->
        <div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <!-- Modal Body -->
                    <div class="modal-body">
                        @Html.Partial("~/Views/Account/Login.cshtml")                         
                    </div>
                </div>
            </div>
        </div>
        <!-- /Subscribers popup -->
        @RenderBody()
    </div> 

here how looks Login.cshtml:

@model GeomindEnterprise.Models.LoginViewModel

<div class="row">
    <div class="col-md-6 col-sm-6 col-xs-6">
        <!-- /SOCIAL LOGIN -->
        @using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "sky-form", role = "form" }))
        {
            @Html.AntiForgeryToken()

            @Html.ValidationSummary(true, "", new { @class = "text-danger" })

            <label class="input margin-bottom-10">
                <i class="ico-append fa fa-envelope"></i>
                @Html.TextBoxFor(m => m.UserName, new { @placeholder = "Email" })
                @Html.ValidationMessageFor(m => m.UserName, "", new { @class = "text-danger" })
            </label>

            <label class="input margin-bottom-10">
                <i class="ico-append fa fa-lock"></i>
                @Html.PasswordFor(m => m.Password, new { placeholder = "Password" })
                @Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" })
            </label>

            <label class="form-group">
                @Html.CheckBoxFor(m => m.RememberMe, new { @class = "col-md-1" })
                @Html.LabelFor(m => m.RememberMe)
            </label>

            <footer>
                <button type="submit" class="btn btn-default noradius pull-right"><i class="fa fa-check"></i> OK, LOG IN</button>
            </footer>
        }
    </div>

</div>

also in layout page I have this navigation bar:

            <div class="navbar-collapse pull-left nav-main-collapse collapse">
                <nav class="nav-main">
                    <ul id="topMain" class="nav nav-pills nav-main">
                        <li>@Html.ActionLink(@Resources.Resources.Home, "Index", "Home")</li>
                        <li>@Html.ActionLink(@Resources.Resources.About, "About", "Home")</li>
                        <li>@Html.ActionLink(@Resources.Resources.Contact, "Contact", "Home")</li>
                        <li><a href="#" data-toggle="modal" data-target="#myModal">@Resources.Resources.Subscribers</a></li>
                        @if (Request.IsAuthenticated && User.IsInRole("Admin"))
                        {
                            <li>@Html.ActionLink("Back office", "BackOfficeMain", "BackOffice")</li>
                            <li>@Html.ActionLink("RolesAdmin", "Index", "RolesAdmin")</li>
                            <li>@Html.ActionLink("UsersAdmin", "Index", "UsersAdmin")</li>
                            <li>@Html.ActionLink("GroupsAdmin", "Index", "GroupsAdmin")</li>
                        }
                    </ul>
                </nav>
            </div>

While when I click Back office or RolesAdmin or UsersAdmin or GroupsAdmin I get this error:

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[GeomindEnterprise.Models.ApplicationUser]', but this dictionary requires a model item of type 'GeomindEnterprise.Models.LoginViewModel'.

on this row:

@Html.Partial("~/Views/Account/Login.cshtml")

Any idea why I get error above and how can I prevent the error above?

Michael
  • 13,950
  • 57
  • 145
  • 288
  • `@Html.Partial("~/Views/Account/Login.cshtml", new LoginViewModel())` –  Nov 13 '17 at 08:54
  • But why would you want to render all that extra html in all your views (a user only logs in once) - you should consider using ajax to load the form into the view only when needed. –  Nov 13 '17 at 08:56
  • can you please show example how to implement it?Im new in mvc technology – Michael Nov 13 '17 at 09:01
  • Do you mean using ajax to load the login form? –  Nov 13 '17 at 09:02
  • yes how ajax to load the login form. – Michael Nov 13 '17 at 09:08
  • Well thats a separate question. But you want a `[HttpGet]public Action Login()` method that returns a partial view of your login form (including the html for the modal), and in you layout, add (say) `Login` and `$('#login').click(function(){ var url = '@Url.Action("Login")'; $.get(url, function(response) { $(someElement).html(response); });` –  Nov 13 '17 at 09:12
  • That is the basics, but also suggest you read [this answer](https://stackoverflow.com/questions/31768946/required-field-validations-not-working-in-jquery-popup-mvc-4/31769058#31769058) for client side validation –  Nov 13 '17 at 09:14

0 Answers0