部分观点互相干扰

发布于 2024-11-03 06:30:39 字数 2095 浏览 2 评论 0原文

我有以下 _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) 中的 LoginRegister 部分显示验证错误,例如“电子邮件不能为空” 。我知道无论回发什么部分,都会呈现视图,但必须有一种方法来防止这种情况发生...我是否必须摆脱部分并将所有内容渲染到 _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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许你一世情深 2024-11-10 06:30:40

您是否有不同的搜索形式以及“userPanel”中的内容?您可能需要确保您的搜索是获取而不是发布。

 @using (Html.BeginForm("Search", "YourController", FormMethod.Get))

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))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文