In my ASP.NET MVC2 application, I have a ViewModel class called UserCreateViewModel.
There are a number of properties in this class that map directly to the LINQ to SQL class called User. I use AutoMapper to do this mapping, and it works great.
In my Create UserController action, I get a partially populated UserCreateViewModel that contains OpenId authentication information.
this is the definition of UserCreateViewModel:
public class UserCreateViewModel { public string OpenIdClaimedIdentifier { get; set; } public string OpenIdFriendlyIdentifier { get; set; } public string Displayname { get; set; } public string Email { get; set; } public string PhoneNumber { get; set; } }
In the Create view, I do not want OpenIdClaimedIdentifier or OpenIdFriendlyIdentifier to be editable.
I used a strongly typed creation view (using the built-in automatic creation), but this gives me an editable text file for these two properties. If I completely remove the specific html when the creation form returns (and returns directly to the UserCreateViewModel):
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(UserCreateViewModel viewModel, string ReturnUrl)
the returned viewModel does not contain values ββfor OpenIdClaimedIdentifier and OpenIdFriendlyIdentifier .
I explored the use of the [HiddenInput] attribute, but I did not seem to be able to do the job. I also tried using the hidden <input/> in the form, which works, but it seems a bit awkward.
Is there a better way to do this? or uses a hidden <input> only way?
EDIT: To clarify the logical flow:
- A user is trying to log in using his OpenId.
- DotNetOpenAuth authenticates and, if successful, returns
OpenIdClaimedIdentifier and OpenIdFriendlyIdentifier . - I am doing a database check to see if there is already a user with this identifier.
- If the user no longer exists, create a temporary
UserCreateViewModel with the OpenId fields set. This is stored in TempData . - Redirect to UserController. Create an action and display the Create view using this partially completed
UserCreateViewModel . - This bit is a problem. The user then completes the other data (DisplayName, etc.) and publishes the resulting
UserCreateViewModel .
The problem is that between steps 5 and 6, the OpenId parameters are lost if they are not connected. I donβt want to show the user OpenIdClaimedIdentifier or OpenIdFriendlyIdentifier during the creation of the form, but if I delete the data, their binding will be lost in the message.
Hope this simplifies the question a bit.