我是MVC的新手,我无法找到解决问题的方法。我想从另一个控制器调用非操作方法(返回字符串,整数等)。可能吗?如何正确地做?我正在使用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!
}
}
对不起,我的英语,非常感谢您的答复!:)
让控制器调用其他控制器的实例方法不是最佳设计。我建议您将方法添加GetShopId
到,IShopRepository
以便使用存储库的每个组件都可以访问它(包括您的其他控制器)。IShopRepository
毕竟,此方法所属的是。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句