简体   繁体   中英

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? 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM