【发布时间】:2019-02-23 06:05:45
【问题描述】:
我在HomeController 中有一个操作,Dependency Injecttion 在Asp.Net Core 2.1.0 Razor Page 中。
操作代码
private readonly Test.Data.MyContext _Context;
public HomeController(Test.Data.MyContext context)
{ _Context = context; }
[HttpGet]
public ActionResult TypeofAccounts(string at)
{
var result = _Context.TypeOfAccounts
.Where(x => x.AccountType == at)
.Select(x =>
new
{
label = x.AccountType,
id = x.AccountType
}
);
return Json(result);
}
我想在各种Razor PageModel 中使用这个结果。我怎样才能达到。这是示例 Razor 页面。
public class IndexModel : PageModel
{
private readonly Test.Data.MyContext _Context;
public IndexModel(Test.Data.MyContext context)
{ _Context = context; }
public void OnGet()
{
// Here I want bind HomeController's action.
}
}
我尝试使用var ta = new Test.Controllers.HomeController().TypeofAccounts("B001");,但没有成功。
【问题讨论】:
标签: c# asp.net-core-2.1 razor-pages