gpt4 book ai didi

c# - MVC 3 多表单模型传递给字典

转载 作者:太空宇宙 更新时间:2023-11-03 14:06:05 25 4
gpt4 key购买 nike

我是 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 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>

第二个在搜索框中:

@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 和 SearchBox 添加它们自己的字典:

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

有没有人知道如何解决这个问题?非常感谢。

最佳答案

@{Html.RenderPartial("MenuTop", new Models.LogOnModel());}
@{Html.RenderPartial("SearchBox", Enumerable.Empty<Product>());}

关于c# - MVC 3 多表单模型传递给字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9274826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com