部分观点互相干扰
我有以下 _Layout.cshtml 页面,其中有一堆对多个部分视图的 @Html.Action()
调用。
<div class="wrapper">
<div class="header">
<a style="text-decoration:none;" href="@Url.Action("Index", "Home")"><div class="logo"><p>fisharwe</p><span class="greenText float-right">:</span></div></a>
<div class="searchBar">
@Html.Action("Search", "Item")
</div>
<div id="hearGreenBar"></div>
</div>
<div class="pageContent">
@RenderBody()
</div>
<div class="rightColumn">
<div id="help">
<div id="allHelpContent">
<span id="helpIcon"></span> <span id="helpTitle">help</span> <span id="helpArrow"></span>
</div>
</div>
<div id="userPanel">
@if(!Request.IsAuthenticated)
{
<div id="loginForm">@Html.Action("Login", "User")</div>
<div id="registerForm">@Html.Action("Register", "User")</div>
<hr class="greyLine" />
<div id="recentlyViewedItems">
<div id="recentItemsTitle">
<span class="recentItemsIcon"></span><span class="theRecentTitle">Recently Viewed</span>
</div>
</div>
}
else
{
<div id="userInfoSummary">@Html.Action("Summary", "User")</div>
}
</div>
</div>
</div>
在顶部,您可以看到 @Html.Action("Seach", "Item")
调用,它呈现搜索栏并允许用户搜索项目/类别/子类别...等。我现在可以正常工作了,但它产生了一个新问题!当用户搜索某些内容并呈现结果时,侧边栏 (userPanel) 中的 Login
和 Register
部分显示验证错误,例如“电子邮件不能为空” 。我知道无论回发什么部分,都会呈现视图,但必须有一种方法来防止这种情况发生...我是否必须摆脱部分并将所有内容渲染到 _Layout.cshtml 页面中?但在这种情况下,我需要输入此页面,这将导致另一个问题......那么可以做什么呢?我愿意接受任何建议...
谢谢。
I have the following _Layout.cshtml page that has a bunch of @Html.Action()
calls to several partial views.
<div class="wrapper">
<div class="header">
<a style="text-decoration:none;" href="@Url.Action("Index", "Home")"><div class="logo"><p>fisharwe</p><span class="greenText float-right">:</span></div></a>
<div class="searchBar">
@Html.Action("Search", "Item")
</div>
<div id="hearGreenBar"></div>
</div>
<div class="pageContent">
@RenderBody()
</div>
<div class="rightColumn">
<div id="help">
<div id="allHelpContent">
<span id="helpIcon"></span> <span id="helpTitle">help</span> <span id="helpArrow"></span>
</div>
</div>
<div id="userPanel">
@if(!Request.IsAuthenticated)
{
<div id="loginForm">@Html.Action("Login", "User")</div>
<div id="registerForm">@Html.Action("Register", "User")</div>
<hr class="greyLine" />
<div id="recentlyViewedItems">
<div id="recentItemsTitle">
<span class="recentItemsIcon"></span><span class="theRecentTitle">Recently Viewed</span>
</div>
</div>
}
else
{
<div id="userInfoSummary">@Html.Action("Summary", "User")</div>
}
</div>
</div>
</div>
At the top you can see the @Html.Action("Seach", "Item")
call which renders a search bar and allows users to search for items/categories/sub-categories...etc. I got this working now, but it generated a new problem! When the user searches for something, and the results are rendered, the Login
and Register
partials in the sidebar (userPanel) are displaying validation errors such as "Email cannot be empty". I understand that the View is rendered regardless of what partial posted back but there has to be a way to prevent that from happening... Do I have to get rid of partials and render everything into the _Layout.cshtml page? But in that case I need to make this page typed which will cause yet another issue... So what can be done? I'm open to any suggestions...
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否有不同的搜索形式以及“userPanel”中的内容?您可能需要确保您的搜索是获取而不是发布。
Do you have different forms for the search and what is in the "userPanel"?. You may want to make sure your search is doing a get and not a post.