Results 1 to 3 of 3

Thread: [RESOLVED] Controller for editing MembershipUser details?

  1. #1

    Thread Starter
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Resolved [RESOLVED] Controller for editing MembershipUser details?

    I just got started on learning MVC, so my first task was to create an interface for managing MembershipUser accounts.

    I have a GET controller for /Account/Edit/{id} and a POST controller for /Account/Edit. How do I pre-populate the View fields on the Edit View with the existing values (from the GET controller)? I'm guessing I would set the values for the EditUserModel that is attached to the View, but I'm not sure where/how I do this.

    The EditUserModel doesn't have a parameter for UserName, because that can't be modified on the account. How do I send the id to the POST controller so it knows which account to update?

    What's the best thing to be sending for the id parameter to identify the user account? I don't really want to be putting the UserName directly into the URL. Is it better to use the MembershipUser.ProviderUserKey field?
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Controller for editing MembershipUser details?

    First up, you mean "action" where you keep saying "controller". The class is the controller and the methods are the actions.

    As for the question, any value you want sent back to the controller when you post must be contained in a form field. As such, any values that aren't being edited should be associated with 'hidden' fields. The value of each hidden field is contained in the data posted back to your controller action, just like each input field or the like, but they are not displayed to the user. That's how you pass a PK from an action to a view and then to another action. If you're using the inbuilt ASP.NET membership functionality then it's the user name you'll want to use to identify an account.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: Controller for editing MembershipUser details?

    Thanks for the clarifications. I've got it working following your suggestion, but I decided to use the ProviderUserKey instead of the UserName as I didn't want the UserName appearing in URLs (eg. in the URL link going from the View listing the users to the Edit action /Account/Edit/{id}).
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width