[英]Model View Controller Service Connection (ASP.NET Core)
MyInvestmentRepo myInvestmentRepo = new InvestmentInstrumentServices();
[HttpGet]
public IActionResult List()
{
var investment = myInvestmentRepo.GetInvestmentInstrumentsList();
return View(investment);
}
private InvestmentInstrumentServices _invServices;
MyCommentaryRepo myCommentaryRepo = new UserCommentaryService();
[HttpGet]
public IActionResult IList()
{
var commentary = myCommentaryRepo.GetUserCommentaryList();
return View(commentary);
}
private UserCommentaryService _commServices;
I have controller and service files.Is there a way to connect two different services from a single controller file?我有 controller 和服务文件。有没有办法从一个 controller 文件连接两个不同的服务? it doesn't work for me when I try it like this.
当我这样尝试时,它对我不起作用。
If I understand your question, you can use ViewData Or ViewBag to send data to view like Code below:如果我理解您的问题,您可以使用 ViewData 或 ViewBag 发送数据以查看如下代码:
public IActionResult IList()
{
var commentary = myCommentaryRepo.GetUserCommentaryList();
var investment = myInvestmentRepo.GetInvestmentInstrumentsList();
ViewData["investment"] = investment ;
return View(commentary);
}
You can see this link for more help: click here您可以查看此链接以获取更多帮助: 单击此处
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.