简体   繁体   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;

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.

相关问题 在视图中找不到ASP.Net核心模型 - ASP.Net core model not found in view 将两个或多个参数从 model 视图传递到 EF Core / ASP.NET Core MVC 应用程序中的 controller - Passing two or more parameters from model view to controller in EF Core / ASP.NET Core MVC application ASP.NET MVC Core TextBoxFor event pass model from View to Controller - ASP.NET MVC Core TextBoxFor event pass model from View to Controller Model 列表返回为 null 从视图到 controller Z9E0DA8438E1E38A1C30F4B76ZCE3 核心 - Model List returning as null from view to controller ASP.NET Core MVC 从 controller 返回 viewmodel 作为 model 以查看和获取 angularjs 并显示在 Asp.Net Core 3.1 的选项标签中? - return viewmodel as a model from controller to view and geting with angularjs and show in option tag in Asp.Net Core 3.1? ASP.NET CORE,查看 model 的所有字段为 null 时传递回 Z9BBF373797BF7CF7BA62C80023 - ASP.NET CORE, View model has all fields as null when passed back to Controller ASP.NET 核心 MVC - 将 Model 数据从视图传递回 Controller - ASP.NET Core MVC - Passing Model Data Back to Controller from View 在ASP.NET Core中使用视图模型插入两个表/数据库连接问题 - Inserting into two tables using a view model in asp.net core/ issue with database connection How can you maintain model state in ASP.NET Core between repeatedly displaying the Model in a View and sending the model back to the Controller? - How can you maintain model state in ASP.NET Core between repeatedly displaying the Model in a View and sending the model back to the Controller? 访问ASP.NET核心控制器内的连接字符串 - Access Connection String inside an ASP.NET Core controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM