|
-
Apr 28th, 2011, 10:24 PM
#1
[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?
-
Apr 29th, 2011, 12:43 PM
#2
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.
-
May 3rd, 2011, 06:46 PM
#3
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}).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|