开发者

asp.net MVC : capture Html.BeginForm with different action

I render a view through my controller like so:

public ViewResult Forum([DefaultValue(0)]int id)
        {
            ForumMessagesViewModel forumMsgs = new ForumMessagesViewModel(_articles.GetAllForumMessages());
            return View(forumMsgs);
        }

Inside that view .aspx, I want to enable message posting. So I created the following form:

<% using (Html.BeginForm("AddForumMessage", "Home"))
       { %>
        <fieldset>
            <开发者_StackOverflow中文版;legend>add message</legend>

                    <label id="NameLabel">name:</label>
                    <%= Html.TextBoxFor(model => model.newMessage.MessagePosterName) %>      

                    <label id="TitleLabel">subject:</label>
                    <%= Html.TextBoxFor(model => model.newMessage.MessageSubject)%>

                    <label id="ContentTextLabel">contents:</label>
                     <%= Html.TextBoxFor(model => model.newMessage.MessageContents)%>

                    <%= Html.HiddenFor(model => model.parentMessageID, 0) %>


                <div>
                    <input type="submit" value="submit"/>
                </div>

        </fieldset>


    <%} %>

The idea is to capture the above form with this Action (in the home controller):

[HttpPost]
public ActionResult AddForumMessage(ForumMessagesViewModel newMessage)
{
    /* Add new forum message to DB */


    return Forum(0);

}

but the "Forum" action (which generated the view) always captures it instead.

What am I doing wrong?

Thank you,

Tom


Weird. Look at the generated markup to see if the correct URL is being rendered in the <form> tag.

Also, try the alternative:

<% Html.BeginForm("..", ".."); %>

<% Html.EndForm(); %>


Not sure if you've already solved this since it is long ago, but maybe someone else has the same issue.

I just ran into the same problem, also with creating a forum, my quickreply action kept getting picked up by my forum or thread action. All I did was swap around some routes, put the thread and forum ones to a lower position, and that did the trick.

Hope that helps,

Lauw

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜