What you want to do is not common. If you write more about what you want exactly, we can help better. Below is what you're trying to do. A view is invoked by System.Web.Mvc.Html.Action. That is, if the code below is useful for something, can only be used in a controller. In the example I'm in the SomeController calling the action "About" the controller "Home" using the extension you want to create.
The Extension Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
namespace StackOverflow.Controllers
{
public static class ControllersExtensions
{
public static ActionResult Index(this HomeController controller, string ViewName)
{
string controllerName = controller.GetType().Name.Replace("Controller", "");
RouteValueDictionary route = new RouteValueDictionary(new
{
action = ViewName,
controller = controllerName
});
RedirectToRouteResult ret = new RedirectToRouteResult(route);
return ret;
}
}
}
The SomeController:
namespace StackOverflow.Controllers
{
public class SomeController : Controller
{
//
// GET: /Some/
public ActionResult Index()
{
HomeController home = new HomeController();
return home.Index("About");
}
}
}
The Home Controller:
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View();
}
public ActionResult About()
{
ViewBag.Message = "Your app description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}