0

I have a HTML.BeginForm() to change user's data (email, password etc) but I want to separate the contents at the same page, I mean that there will be:

MainContent with submit button and also
   - a HTML.BeginForm() with fields to change password + submit button
   - a HTML.BeginForm() with fields to change email + submit button

the thing is, I want to allow user to change his password without sending all form data to the controller, only data from the password fields.

That View inherits from my buisness object with properties (Login, Password, Email etc)

Any ideas how to do that will be so helpful. Thanks !

4
  • 1
    This already works just as you described it (multiple Html.BeginForm() s.). But "MainContent with submit button" - what's that submit button for? Commented Oct 22, 2010 at 13:37
  • You just have to use the overload which lets you specify the action. Commented Oct 22, 2010 at 13:39
  • bzlm >> for send all form data (from also from other forms) Commented Oct 22, 2010 at 14:07
  • You can't have nested forms in HTML. RTFM. :) If you want an all-encompassing form - which will be harder to model bind in ASP.NET MVC - you should only BeginForm() once. But I'd use some fancy client-side magicke instead. Commented Oct 22, 2010 at 17:08

1 Answer 1

3

If you want to avoid POSTing all data, make a separate controller action for each of the types of form submission you want to make

class Mycontroller
{
  [HttpPost]
  public ActionResult ChangeEmail(int id,string email)
  {
    // modify email for user with id id

  }

  [HttpPost]
  public ActionResult ChangePassword(int id,string password)
  {
    // modify password for user with id id

  }
}

You can specify which action a form submits to with an argument like this:

Html.BeginForm("ChangeEmail") 
Sign up to request clarification or add additional context in comments.

2 Comments

nope, it still sends all form data and doesn't go into ChangePassword action (doesn't "see" it)
look at the generated html, is there a form tag with action="ChangePassword" ?

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.