ASP .NET MVC 2.在AjaxOptions中使用InsertionMode.Replace是正确的

时间:2022-03-01 06:49:59

I am trying to replace <div> content after a form submit. Here is the code (it is a partial view):

我试图在表单提交后替换

内容。这是代码(它是局部视图):

    <% using (Ajax.BeginForm("Authenticate", "User", new AjaxOptions { HttpMethod = "post", UpdateTargetId = "authPanel", InsertionMode = InsertionMode.Replace}))
{%>
    <label>Username</label><%= Html.ValidatedTextBoxFor(username => Model.UserAuthienficateDto.Username, false) %>
    <label>Password</label><%= Html.ValidatedTextBoxFor(password => Model.UserAuthienficateDto.Password, false) %>
    <input name="Input" type="submit" class="button" value="Authenticate" />
<%}%>
<div id="authPanel">
<ul>
    <% if (HttpContext.Current.User.Identity.IsAuthenticated)
    {%>
        <li class="nonregister">Logged in as <%=HttpContext.Current.User.Identity.Name%></li>
        <li class="register"><%= Html.ActionLink("Logout", "Logout", "User")%></li>
    <%
        }%>
    <% else
    {%>
        <li class="nonregister">Not a member &nbsp;?</li>
        <li id="userRegisterDialogOpener" class="register">Sign up now!</li>
    <%}%>
</ul>
</div>

The problem is that after form submit I get whole partial view re-rendered. Also all the results are being rendered above the old ones (they have some offset though). Why InsertionMode.Replace is not working properly? Mant thanks in advance for your help.

问题是在表单提交后我得到了整个局部视图重新渲染。此外,所有结果都呈现在旧的结果之上(尽管它们有一些偏移)。为什么InsertionMode.Replace无法正常工作? Mant事先感谢你的帮助。

1 个解决方案

#1


0  

I have solved the problem by separating form and authPanel to different partial views.

我已经通过将form和authPanel分成不同的局部视图来解决了这个问题。

#1


0  

I have solved the problem by separating form and authPanel to different partial views.

我已经通过将form和authPanel分成不同的局部视图来解决了这个问题。