Posting a form with anchor link at the end?
I have a form for comments like the one below but after the form is posted I wish to navigate to http://www.myurl.com/mypage#commentform but I don't know how to do this. Instead of changing my form maybe there is a way to return a View with my model and add #commentform to my 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>
It seems you are trying to keep the position of the page on the same spot after submit. This could be achieved using an AJAX form.
<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>
This is how I'd do it.
<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>
I'm assuming you are not doing any redirects on success and that your url in your question corresponds to the page you want to access.
精彩评论