2
我对MVC 3相当陌生,而且我遇到了一个问题。主要布局如下:MVC 3多表单模型传递到字典
<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>
我在页面上有3个表单。第一是在MenuTop视图:
@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>
第二个是在搜索盒:
@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>
当然形式在RenderBody,根据上下文而变化的和。 问题是,当我从RenderBody()发布某些表单时,例如。注册,我收到以下错误:
The model item passed into the dictionary is of type 'Models.RegisterModel', but this dictionary requires a model item of type 'Models.LogOnModel'.
我试图添加到MenuTop和搜索盒自己的字典:
Html.RenderPartial("MenuTop", new ViewDataDictionary(Models.LogOnModel))
Html.RenderPartial("SearchBox", new ViewDataDictionary(IEnumerable<Product>))
但在这种情况下,我得到以下错误:
CS0119: 'Models.LogOnModel' is a 'type', which is not valid in the given context
有没有人有任何想法,如何解决这个问题?非常感谢。
谢谢,它现在完美的工作。 – Andree 2012-02-14 11:07:22