I have a GenericController which has the following methods:
public class GenericGridController<T, TKey>:Controller
where T : class
where TKey : IComparable
{
string GetFilterParam();
string GetGridPartialName();
List<T> GetGridModel(TKey param);
List<T> GetGridModel(T entity);
ActionResult GetGrid(TKey param);
ActionResult Add(T entity);
ActionResult Edit(T entity);
ActionResult Delete(T entity);
}
When ever I need to create a grid, I am creating a new controller, inherited from the GenericGridController and I need to override the GetFilterParam and GetGridParialName, to provide the specific names.
This is working just fine. Now I want to not override the 2 methods, and:
I was trying to do "something which I do not understand": - I made 2 string properties in the generic controller - I initialized them from the constructor, something like:
public string FilterParam { get; set; }
public string GridPartialName { get; set; }
public GenericGridController(string filterParamName, string partialName)
{
FilterParam = filterParamName;
GridPartialName = partialName;
}
then I create a new TestController, inherited from the GenerigGridController, and I saw that he ask to implement the missing contructor, something like this:
public class TestController : GenericGridController<Candidat,int>
{
public TestController(string filterParamName, string partialName)
: base(filterParamName, partialName)
{
}
}
I was expecting to do something like this:
public class TestController : GenericGridController<Candidat,int>("param","PartialView"){}
My question is: How to provide the 2 parameters need it in the GenericGridController constructor.
Maybe is a stupid question, I am just trying to understand how this works.