我将有一个订阅流程,如下所示:
-
用户进入定价页面,选择计划,重定向到../register?平面=1
-
用户注册用户名和密码,转发到计费页,需要…./subscription/billing?平面=1
-
我在注册表视图模型中添加了一个整数planid。
在定价页面上,我的链接工作正常。
对于寄存器控制器,我有:
[AllowAnonymous]
public ActionResult Register(RegisterViewModel model, int planId)
{
if (Request.IsAuthenticated) {
return RedirectToAction("Pricing", "Home");
}
RegisterViewModel model1 = new RegisterViewModel();
model1.planId = Convert.ToInt32(Request.QueryString["planId"]);
return View(model1);
}
在注册视图中,我有:
@Html.HiddenFor(m => m.planId)
但是,每次运行应用程序时,此值都为空。如果我可以将计划作为注册表表单提交的一部分包括在内,那么我想我可以将控制器重定向到“../subscription/billing”?登记后,平面=1“。
这是当前的寄存器post控制器,我认为我只需要将planid添加到redirecttoaction中:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email, Role = "Admin", ReportsTo = "", ActiveUntil = DateTime.Now.AddDays(-1) };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
// Send an email with this link
// string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
// var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
// await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
return RedirectToAction("Pricing", "Home");
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
我的问题是,如何让planid从查询字符串传递到登录表单中的隐藏字段?