开发者

Html.BeginForm in partial for a different controller

开发者 https://www.devze.com 2023-01-05 05:09 出处:网络
I have the following code: <% using (Html.BeginForm(\"AddComment\", \"Comments\", FormMethod.Post)) { %>

I have the following code:

<% using (Html.BeginForm("AddComment", "Comments", FormMethod.Post)) { %>
<div id="New_Comment">
<textarea name="newComment" id="newComment">Add comments</textarea>
<input type="submit" value="Add" />
<div><span class="text_grey">Attach:</span><a href="#" class="link_text_grey">File</a> <a href="#" class="link_text_g开发者_Python百科rey">Link</a></div>
</div>
<%} %>

This is in a partial rendered by the MyPage controller. For some reason the action on the form comes out blank, if I reference a method on the MyPage controller it works fine what I want to do is point to a different controller with my form.


To solve this issue I simple added in an area route value like so:

new { area = "" }

With the empty string directing the route to the default area.


1) Is your "Comments" action marked as being a POST action?

2) Also

Try just doing:

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

// Html and script

<% Html.EndForm(); %>

I know that there shouldn't be difference between what you have and what I suggest, but it's worth a try.

0

精彩评论

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

关注公众号