【发布时间】:2015-02-01 20:05:45
【问题描述】:
我是 MVC 新手,我找不到解决问题的方法。我想从另一个控制器调用非操作方法(返回字符串、int 等)。甚至可能吗?如何正确地做到这一点?我正在使用 ninject,我的控制器如下所示:
public class ShopController : Controller
{
private IShopRepository repository;
public ShopController(IShopRepository shopRepository)
{
this.repository = shopRepository;
}
public int GetShopId(string shopName)
{
// how to call this method from another controller?
// here is linq query which needs shop table repository!
}
}
抱歉我的英语不好,非常感谢您的回复!:)
【问题讨论】:
-
只需将此非操作方法声明为静态
标签: asp.net-mvc asp.net-mvc-4 ninject