[英]How send an ActionResult from a ClassLibrary project to another project?
我将Identity类和AccountController移到新的ClassLibrary中,一切正常,除了两件事。 我注意到的第一件事是在调用Register方法时收到此警告
这是警告显示的代码,它现在为空,因为我只是想确保可以访问Register方法,并且确实可以访问AccountController类中的Register方法。
public void CreateNewAdministrator(NewAdministrator administrator)
{
#region Initialization
RegisterViewModel rvm = new RegisterViewModel();
#endregion
AccountController.Register(rvm);
}
我要遇到的第二个问题是Register方法本身,这是Register方法
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(“ Index”,“ Home”);
我需要它返回到MainProject区域中的视图,另一件事是,如果我可以从调用它的位置调用它来调用视图,则我不希望它引起视图的刷新。 我正在使用JQuery Ajax调用此方法,因此添加新记录时页面不会刷新。
我知道我将再遇到另一个问题,但这可能是另一个问题。
如警告所述,您将需要await
AccountController.Register(rvm);
。
这样做是为了使当前方法在Register
方法完成之前不会继续执行。这还可以解决您的第二个问题,因为这可能是由该问题引起的。
另外,请提供您收到的所有警告,错误和/或异常的纯文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.