我有以下控制器方法
public class EmailController : Controller
{
public async Task<ActionResult> SendEmail(UserData user)
{
...
return View(user);
}
}
我正在尝试调用上面的SendEmail
方法并在下面的webapi控制器方法中发送sampleData
对象
[Authorize]
[RoutePrefix("api/Account")]
public class AccountController : ApiController
{
// POST api/Account/Register
[AllowAnonymous]
[Route("Register")]
public async Task<IHttpActionResult> Register(RegisterBindingModel model)
{
// Email Sending
UserData sampleData = new UserData();
sampleData.Id = user.Id;
sampleData.UserName = user.UserName;
sampleData.UserEmail = user.Email;
sampleData.FirstName = user.FirstName;
sampleData.Password = model.Password;
//Call to Async Controller method
var emailSend = await EmailController.Sendemail(sampleData);
}
}
我该怎样才能正确地做到这一点
答案 0 :(得分:0)
SendEmail
上的EmailController
方法是ActionResult
,因此它应该只关注执行更新视图所需的逻辑。任何发送电子邮件的业务逻辑都应该封装在一个单独的层中,可以从视图控制器和API控制器中调用它。