开发者

Html.RenderAction() in ASP.NET MVC 3

开发者 https://www.devze.com 2023-04-11 01:07 出处:网络
In my layout I\'m using RenderAction that will output a simple email form which will post to an action.

In my layout I'm using RenderAction that will output a simple email form which will post to an action.

// In _Layout.cshtm开发者_Go百科l
@{Html.RenderAction("Email", "Home")};

// Home Controller
[ChildActionOnly]
public ActionResult Email(){}

[HttpPost]
public ActionResult Email(params){}

Now the RenderAction works great when it's the only form on the page. If it's not, however, the Email Post action gets called in addition to the other form action which I don't understand. The forms are not nested; the source looks something like this:

<form id="email-form" action="/home/email" method="post">
// form elements
</form>

<form id="some-other-form" action="/somecontroller/someaction" method="post">
// form elements
</form>

How can I avoid the post of the child action when it comes from a different form? As a workaround I can check the paramaters passed in and if they're null I should be fine and dandy, but I don't think this is the intended behavior.


this.ControllerContext.IsChildAction; in your controller will give you the ability to check if the post is coming from the URL or through a Html.RenderAction.

That might help you debug it a little better.

0

精彩评论

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