Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hello
I am new to MVC web development so I am trying to discover this pattern.
I tried to create a new MVC application that navigate between pages.So I create 3 views (home,product,about) and a controller (Site)"The example is taken from the last lab Learn MVC (Model view controller) Step by Step in 7 days – Day 2[^]
 
code of the controller:
 
public class SiteController : Controller
   {
       //
       // GET: /Site/
 
       public ActionResult GoTohome()
       {
           return View("Home");
       }
       public ActionResult AboutUs()
       {
           return View("About");
       }
       public ActionResult SeeProduct()
       {
           return View("Product");
       }
 
I am sure that i didn't get the routing staff because when debugging I get "The view 'Home' or its master was not found. The following locations were searched"
I have modified the global.asax file like this
 
public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
 
            routes.MapRoute(
                 "Default", // Route name
                 "{controller}/{action}/{id}", // URL with parameters
                 new { controller = "Site", action = "GoTohome", id = UrlParameter.Optional } // Parameter defaults
             );
 

Thank you for your help.
Posted 18-Feb-13 1:42am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

 new { controller = "Site(controler name) ", action = "GoTohome(action name)", id = UrlParameter.Optional } 
check this part ....
 
if home is view than action name must be home..
 
 new { controller = "Site ", action = "home", id = UrlParameter.Optional } 
  Permalink  
v2
Comments
simaodinho at 18-Feb-13 9:47am
   
Yes Home is a view so I renamed the "Gotohome" action to "Home" as you said but i got the same error!!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I found the error,I have to add a folder named Site into the Views folder.However i didn't get why i should add this folder because Site is the name of the controller not the folder
 
any explanation
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 450
1 OriginalGriff 180
2 DamithSL 130
3 Dave Kreskowiak 120
4 Suvendu Shekhar Giri 110
0 OriginalGriff 7,645
1 DamithSL 5,614
2 Sergey Alexandrovich Kryukov 5,344
3 Maciej Los 4,961
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100