Reputation: 1199
I'm quite new to MVC 3 and I'm stuck on an issue. The main layout look like this:
<body>
<div id="conteiner_body">
<div id="conteiner_main">
<div id="container_top">
@{ Html.RenderPartial("Basket"); }
@{ Html.RenderPartial("MenuTop"); }
</div>
<div id="left_side_border">
<div id="left_side">
@{ Html.RenderPartial("SearchBox"); }
@{ Html.RenderAction("Index", "LeftMenu"); }
</div>
</div>
<div id="content">
@RenderBody()
</div>
@{ Html.RenderPartial("Footer"); }
</div>
</div>
</body>
I have 3 forms on the page. First is in MenuTop view:
@model Models.LogOnModel
<div id="conteiner_menu_top">
<div id="menu_top">
<div id="login">
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@{
using (Html.BeginForm("LogOn", "Account"))
{
@Html.TextBoxFor(m => m.UserName)
@Html.PasswordFor(m => m.Password)
@Html.CheckBoxFor(m => m.RememberMe)
<input type="submit" value="Login" />
<input type="button" value="Registr" onclick="document.location.href = '/Account/Register'" />
}
}
</div>
</div>
</div>
The second is in SearchBox:
@using (Html.BeginForm("Search", "SearchBox"))
{
<div id="search_box">
<h2>Search</h2>
<input name="searchWord" class="text" type="text" />
<a href="rozsirene_vyhledavani">Advanced</a>
<input class="submit" type="submit" value="Search" />
</div>
and of course the form in RenderBody, which changes according to the context. Problem is, when I post some form from RenderBody(), eg. Registration, I recieve following error:
The model item passed into the dictionary is of type 'Models.RegisterModel', but this dictionary requires a model item of type 'Models.LogOnModel'.
I've tried to add to MenuTop and SearchBox their own dictionary:
Html.RenderPartial("MenuTop", new ViewDataDictionary(Models.LogOnModel))
Html.RenderPartial("SearchBox", new ViewDataDictionary(IEnumerable<Product>))
But in this case I get following error:
CS0119: 'Models.LogOnModel' is a 'type', which is not valid in the given context
Has anybody any idea, how to solve this? Thanks a lot.
Upvotes: 2
Views: 1363
Reputation: 1038720
@{Html.RenderPartial("MenuTop", new Models.LogOnModel());}
@{Html.RenderPartial("SearchBox", Enumerable.Empty<Product>());}
Upvotes: 1