【发布时间】:2016-08-02 09:22:21
【问题描述】:
我的 ASP.NET MVC 3 应用程序中有这个简单的类:
namespace My.Project.Controllers
{
public ActionResult Settings()
{
var m = GetUserData(userID);
...
}
private UserModel GetUserData(string id)
{
if (string.IsNullOrEmpty(id))
{
return null;
}
...
}
}
现在,我在应用程序内部创建了一个单独的区域来存放 API。如何调用第一个命名空间中的方法?
namespace My.Project.Areas.api.Controllers
{
public ActionResult Settings()
{
//How to call "GetUserData" from here?
}
}
【问题讨论】:
-
简短回答:您不会在其他控制器中调用操作方法。更长的答案:将共享逻辑拆分到它自己的类中。
标签: c# asp.net asp.net-mvc