-
Feb 17th, 2012, 12:37 PM
#1
Thread Starter
PowerPoster
How ASP.NET MVC Works
I am following the article tr333 recommended here
Has anybody walked through the article? I am here http://www.howmvcworks.net/GettingStarted/CreatingAView and on step 3 below:
Step 3: Create a Controller Action for the View
So now I have my view. I now need to tell its controller to return it when visiting the proper url. So I go to my "ZooController" and added the following:
public ActionResult LookAtTheMonkey()
{
return View();
}
Now that this is done, if you go to "/Zoo/LookAtTheMonkey" you will get a rather bland page...but a page nonetheless.
When he says, "if you go to '/Zoo/LookAtTheMonkey'..." go to it how? If I hit go it says the resource or one of its dependencies isn't found, but the page is right here in Views/Zoo:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
LookAtTheMonkey
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>LookAtTheMonkey</h2>
</asp:Content>
There are 10 kinds of people in this world. Those who understand binary, and those who don't.
-
Feb 17th, 2012, 03:39 PM
#2
Re: How ASP.NET MVC Works
When he says, "if you go to '/Zoo/LookAtTheMonkey'..." go to it how?
by using your web browser... it should be something along the lines of http://yourservername/Zoo/LookAtTheMonkey ...
as shown here in their example online: http://www.howmvcworks.net/Zoo/LookAtTheMonkey <-- how they "went to /Zoo/LookAtTheMonkey"?
-tg
-
Feb 17th, 2012, 03:47 PM
#3
Thread Starter
PowerPoster
Re: How ASP.NET MVC Works
One would think so. But that is exactly what I am trying and I am getting resource or dependency not found. If I try http://localhost:nnnnn/Zoo/LookAtTheMonkey.aspx or http://localhost:nnnnn/Views/Zoo/LookAtTheMonkey.aspx -- Oh, I needed to leave off the .aspx extension. This worked: http://localhost:nnnnn/Zoo/LookAtTheMonkey!!! Thanks for the prompt to keep trying.
There are 10 kinds of people in this world. Those who understand binary, and those who don't.
-
Feb 17th, 2012, 03:58 PM
#4
Re: How ASP.NET MVC Works
yeah... it says to go to zoo/lookatthemoneky ... not lookatthemonkey.aspx ... I didn't realize that's what you were doing.
-tg
-
Feb 19th, 2012, 08:01 PM
#5
Re: How ASP.NET MVC Works
Going to "/Zoo/LookAtTheMonkey" means that you want to call the LookAtTheMonkey action inside the Zoo controller. If you look in your global.asax file, you will see the default route mapping defined in RegisterRoutes() which is "{controller}/{action}/{id}" with the "id" paramater being optional. The great thing about this is you can specify any type for the "id" parameter (if it has a string representation) like string/int/Guid/etc. when you create your action methods.
That site also appears to be quite old, but is still useful for teaching the MVC concepts.
If you are starting out on MVC, I would recommend using the razor view engine instead of the "aspx" view engine. It's got a much cleaner/nicer layout than "aspx" views.
-
Feb 20th, 2012, 02:14 AM
#6
Re: How ASP.NET MVC Works
Originally Posted by tr333
If you are starting out on MVC, I would recommend using the razor view engine instead of the "aspx" view engine. It's got a much cleaner/nicer layout than "aspx" views.
I would have to agree with this. You will find it quite jarring to start with, but it is quickly becoming the default View Engine.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|