Asp.net mvc 2 在末尾发布带有锚定链接的表单?

Asp.net mvc 2 在末尾发布带有锚定链接的表单?,asp.net-mvc-2,Asp.net Mvc 2,我有一个类似下面的评论表单,但是在表单发布后,我希望导航到它,但我不知道怎么做。 与其更改我的表单,不如用我的模型返回视图,并将#commentform添加到我的url <div id="commentform"> <h2>Leave a comment</h2> <% using (Html.BeginForm("Comment","Post", FormMethod.Post)) %> <% { %>

我有一个类似下面的评论表单,但是在表单发布后,我希望导航到它,但我不知道怎么做。 与其更改我的表单,不如用我的模型返回视图,并将#commentform添加到我的url

<div id="commentform">
    <h2>Leave a comment</h2>
    <% using (Html.BeginForm("Comment","Post", FormMethod.Post)) %>
    <% { %>
        <div>
            <%=Html.EditorFor(post => post.Comment) %>
            <div class="editor-button">
                <input type="submit" value="Comment" />
            </div>
        </div>            
    <% } %>    
</div>

留言
评论后)%>

您似乎试图在提交后将页面位置保持在同一位置。这可以通过使用AJAX表单来实现

<div id="commentform">
    <h2>Leave a comment</h2>
    <% using (Ajax.BeginForm("Comment", "Post", new AjaxOptions { UpdateTargetId = "Comment" })) {%></font></font> 
    <% { %>
        <div>
            <%=Html.EditorFor(post => post.Comment) %>
            <div class="editor-button">
                <input type="submit" value="Comment" />
            </div>
        </div>            
    <% } %>    
</div>

留言
评论后)%>

您似乎试图在提交后将页面位置保持在同一位置。这可以通过使用AJAX表单来实现

<div id="commentform">
    <h2>Leave a comment</h2>
    <% using (Ajax.BeginForm("Comment", "Post", new AjaxOptions { UpdateTargetId = "Comment" })) {%></font></font> 
    <% { %>
        <div>
            <%=Html.EditorFor(post => post.Comment) %>
            <div class="editor-button">
                <input type="submit" value="Comment" />
            </div>
        </div>            
    <% } %>    
</div>

留言
评论后)%>
我就是这样做的

<a name="commentform"></a>
<div id="commentform">
    <h2>Leave a comment</h2>
    <% using (Html.BeginForm("Comment#commentform","Post", FormMethod.Post)) %>
    <% { %>
        <div>
            <%=Html.EditorFor(post => post.Comment) %>
            <div class="editor-button">
                <input type="submit" value="Comment" />
            </div>
        </div>            
    <% } %>    
</div>

留言
评论后)%>
我假设您没有在成功时进行任何重定向,并且您的问题中的url对应于您想要访问的页面。

我就是这样做的

<a name="commentform"></a>
<div id="commentform">
    <h2>Leave a comment</h2>
    <% using (Html.BeginForm("Comment#commentform","Post", FormMethod.Post)) %>
    <% { %>
        <div>
            <%=Html.EditorFor(post => post.Comment) %>
            <div class="editor-button">
                <input type="submit" value="Comment" />
            </div>
        </div>            
    <% } %>    
</div>

留言
评论后)%>

我假设您没有对成功进行任何重定向,并且您的问题中的url与您想要访问的页面相对应。

您部分是对的,但这不是我目前正在寻找的。我只想在URL中添加#commentform你说得有点对,但这不是我目前想要的。我只想将#commentform添加到url中,我更改了它,以便使用jQuery更新url。今天晚些时候我将添加代码。我对其进行了更改,以便使用jQuery更新url。今天晚些时候我将添加代码。