簡體   English   中英

Model 查看 Controller 服務連接(ASP.NET Core)

[英]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;

我有 controller 和服務文件。有沒有辦法從一個 controller 文件連接兩個不同的服務? 當我這樣嘗試時,它對我不起作用。

如果我理解您的問題,您可以使用 ViewData 或 ViewBag 發送數據以查看如下代碼:

public IActionResult IList()
{
    var commentary = myCommentaryRepo.GetUserCommentaryList();
    var investment = myInvestmentRepo.GetInvestmentInstrumentsList();
    ViewData["investment"] = investment ;
    return View(commentary);
}

您可以查看此鏈接以獲取更多幫助: 單擊此處

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM