views:

36

answers:

1

Hi, 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 !

+3  A: 

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") 
Henrik
nope, it still sends all form data and doesn't go into ChangePassword action (doesn't "see" it)
Tony
look at the generated html, is there a form tag with action="ChangePassword" ?
Henrik