1

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

// In _Layout.cshtml
@{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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.