how to create 2 controllers with same actionresult 2 views but one implementation
- by amalatsliit
I got a controller in my mvc application like below.
public class BaseController: Controller
{
protected void LogInfo()
{
logger.InfoFormat("[SessionID: {0}, RemoteIP: {1}]", Session.SessionID, Request.UserHostAddress); }
}
public class FirstController : BaseController
{
public ActionResult Index(string name)
{
LogInfo();
getQueryString();
if(IsValidRec())
{
if(Errors()))
{
return View("Error");
}
var viewname = getViewName(name);
return view(viewname);
}
else
return view("NotFound");
}
}
I need to create another controller(SecondController ) with same ActionResult method that FirstController has but without any implementation. Because I dont wont to repeat same code in 2 ActionResult methods.
what is the best way to do that. I tried in following way but I m getting error when I initialize my protected method 'LogInfo()'
public class SecondController : BaseController
{
public ActionResult Index(string name)
{
var firstcontroller = new FirstController();
return firstcontroller.Index(name);
}
}