我将Identity类和AccountController移动到一个新的ClassLibrary中,除了两件事外,一切都很好。我注意到的第一件事是,我得到这样的警告,称注册方法 如何将ActionResult从ClassLibrary项目发送到另一个项目?
时,这里就是警告显示代码,其空,因为现在我只是想确保我能达到注册方法,它确实到达AccountController类中的Register方法。
public void CreateNewAdministrator(NewAdministrator administrator)
{
#region Initialization
RegisterViewModel rvm = new RegisterViewModel();
#endregion
AccountController.Register(rvm);
}
我要遇到的第二个问题是在登记方式本身,这里是注册方法
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email, AccountNumber = model.AccountNumber };
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("Index", "Home");
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
我在哪里预见的问题是
返回RedirectToAction (“索引”,“首页”);
我需要这个返回到MainProject区域中的视图,另一个是如果我可以从它被调用的地方调用视图,我不希望它导致刷新风景。我使用JQuery Ajax调用此方法,以便在添加新记录时不会刷新页面。
我知道我会遇到另一个问题,但这可能是另一个问题。