Question on The HelloWorld View

Jan 4, 2011 at 7:31 PM

I was reading the wiki on custom module (, and it is a great wiki for beginners :)

Since I had some experience with MVC1, 2, and 3RC, I am actually a little puzzled with the View setup. here is the route rules from the wiki

public IEnumerable<RouteDescriptor> GetRoutes()
            return new[] {
                             new RouteDescriptor {
                    Priority = 5,
                    Route = new Route(
                        new RouteValueDictionary {
                            {"area", "HelloWorld"},
                            {"controller", "Home"},
                            {"action", "Index"}
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "HelloWorld"}
                        new MvcRouteHandler())

The route rule basically says that for "default" incoming requests under /helloworld area will trigger Index() action of HomeController. However, under the view, the wiki instruction says to create a "Home" folder (that part makes sense), and then create a view named "HelloWorld.cshtml" Why is the view named "HelloWorld.cshtml", and not "Index.cshtml?" By convention, HomeController triggers Index() action, which should trigger Index view?

This seems to complicate things a bit, because what happens if HomeController supports two actions, such as Index(), and HelloWorld()? Wouldn't the view get confusing?

Thanks for reading!

Jan 4, 2011 at 7:35 PM

Sure, it could be index.cshtml and the action could just return View().

Jan 4, 2011 at 8:37 PM

Ah! oops missed that part in the action method. Thanks for pointing out the obvious.


public class HomeController : Controller {
        public ActionResult Index() {
            return View("HelloWorld");