There are several ways to do what I imagine you want to do, which is to instantiate an object and consume its methods.
Option 1: using the driver's constructor
public class MyOwnController : Controller
{
private MyClass model;
public MyOwnController()
{
model = new MyClass();
}
public ActionResult Index()
{
return View(model.GetInfo());
}
}
Option 2: as property
public class MyOwnController : Controller
{
private MyClass model = new MyClass();
public ActionResult Index()
{
return View(model.GetInfo());
}
}
or
public class MyOwnController : Controller
{
private MyClass model { get { return new MyClass(); } }
public ActionResult Index()
{
return View(model.GetInfo());
}
}
Option 3: class methods
If you are going to execute a method that will return information based on the context, you can choose to leave the method as static
and delegate the task:
public class MyClass
{
public static string GetInfo(string dato1, int dato2...)
{
return ...
}
}
public class MyOwnController : Controller
{
public ActionResult UnaVista(string dato1, int dato2)
{
return View(MyClass.GetInfo(dato1, dato2));
}
}
In fact there are more ways, personally I would recommend using option 3 since it is more focused on the concept of MVC itself.