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=开发者_StackOverflow中文版"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.
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.
@using (Html.BeginForm("Search", "YourController", FormMethod.Get))
精彩评论