【发布时间】:2017-03-09 20:14:44
【问题描述】:
您好,在 ASP.net MVC 网站上工作时,我遇到了一个奇怪的问题。 在重定向到控制器中的另一个动作时,我想添加一个 get 值,我确实喜欢这样做
//
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.UserName, Email = model.Email };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
//await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
return RedirectToAction("ConfirmEmailAwait", "Account", new { userId = user.Id }); //<-----[LOOK HERE]
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
//
// GET: /Account/ConfirmEmailAwait?userId=d178b665-b616-4303-ae7d-00a663014109
[AllowAnonymous]
public async Task<ActionResult> ConfirmEmailAwait(string userId)
{
// 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(userId);
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = userId, code = code }, protocol: Request.Url.Scheme);
string emailHeader = "Confirm your account";
string emailBody = "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>";
await UserManager.SendEmailAsync(userId, emailHeader, emailBody);
return View(userId);
}
据我所知,这段代码完成了它应该做的事情,它将用户发送到正确的 URL,因此它应该可以正常工作。但如果你在这里看这张图片:
构造的 URL:http://localhost:55767/Account/ConfirmEmailAwait?userId=d178b665-b616-4303-ae7d-00a663014109
错误消息:未找到视图“d178b665-b616-4303-ae7d-00a663014109”或其主视图,或者没有视图引擎支持搜索到的位置
你会看到它正在搜索的 View 是我给它的 get 值,我觉得很奇怪。
有人知道发生了什么吗?我只是犯了一个愚蠢的错误而没有看到吗?请帮帮我,提前谢谢你。
【问题讨论】:
-
您不会重定向到视图。您重定向到操作。
-
您需要显示两种控制器方法的代码(不是指向它的图像的链接),以便添加答案
-
@mason 啊谢谢,我现在修好了
-
@StephenMuecke 我更新了问题
标签: c# asp.net asp.net-mvc get