views:

26

answers:

1

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>
A: 

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>
Dustin Laine
You are partly right but it's not what I'm looking for at the moment. I just want to add #commentform to the url
Marcus