Reputation: 822
I have this code snippet in my Controller class:
var userId = _userService.GetUserByActivationCode(model.ActivationCode);
if (userId != null)
{
var verifiedUser = VerifyUserActivationCode(model.ActivationCode, model.DateOfBirth);
resultModel.RedirectUrl = Url.Action(AccountInformationForUserJourneyAction, new { user = verifiedUser});
}
verifiedUser
is populated correctly, but when passed to this action, user is null.
[AllowAnonymous, HttpGet]
public ActionResult AccountInformationForUserJourney(User user) { // code here }
Why is the verifiedUser not passed to the new ActionResult?
Upvotes: 0
Views: 44
Reputation: 879
You are not binding a model to a view, you are creating a URL that will, in this case, need a querystring to pass any data to the new action. If you want to POST a model, you would need a form with a Javascript auto-post function. Anything you pass in the querystring needs to be URL safe and will then bind to the new action using name=value.
This doesn't seem like what you want to do. Either just pass a user id that you can reload in the new action or return the view that you want the user to see (AccountInformation) directly from the action you are already in, then you can bind your model directly to the view.
Upvotes: 0
Reputation: 43860
Change
resultModel.RedirectUrl = Url.Action(AccountInformationForUserJourneyAction, new { user = verifiedUser});
To
resultModel.RedirectUrl = Url.Action(AccountInformationForUserJourneyAction, verifiedUser);
Upvotes: 1