你好,而在ASP.net MVC網站上工作時,我遇到了一個奇怪的問題。 雖然重定向到控制器中的另一個動作我想添加一個get值,我不喜歡這樣爲什麼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' 或它的主人未找到或沒有視圖引擎支持搜索的位置
您會看到它正在搜索的視圖是我給它的獲取值,我覺得很奇怪。
有誰知道發生了什麼事?我只是犯了一個愚蠢的錯誤,沒有看到它?請幫助我,並提前感謝您。
您不重定向到視圖。您重定向到操作。 – mason
你需要顯示兩個控制器方法的代碼(不鏈接到它的圖像),所以可以添加一個答案 –
@mason啊謝謝,我現在修復它 – TheRWS96