Click here to Skip to main content
Click here to Skip to main content

Learn MVC (Model view controller) Step by Step in 7 days – Day 2

By , 28 Apr 2012
 

Learn MVC (Model view controller) Step by Step in 7 days – Day 2 

Contents

So, what’s the agenda?

Lab 6:- Unit test MVC projects
        Step1:- Create the simple display customer screen project
        Step 2:- Add a simple unit test project
        Step 3:- Add appropriate project references
        Step 4:- Write the unit test
        Step 5 :- Finally run the unit test
        So what’s in the next Lab

Lab 7:- Understanding MVC routing
        Introduction
        Step 1:- Take the MVC project created in Day 1.
        Step 2 :- Change global.asax.cs
        Step 3:- Run the application
        So what’s in the next Lab

Lab 8:- Validating and setting default values to MVC URLS
        Step 1:- Create a simple customer model
        Step 2:- Create the controller class
        Step 3:- Apply validation using regex on the MVC routes
        Step 4:- Test if it works
        So what’s in the next lab

Lab 9:- Understanding MVC outbound URLs
        Introduction
        Step 1:- Create views
        Step 2 :- Create controller for the views
        Step 3:- Provide actions in the link
        Step 4:- Enjoy your navigation
       
What’s for third day?          

So, what’s the agenda?

This article is continuation to Learn MVC step by step in 7 days you can read the first day from Click here for Day 1 article.

Get Part 3 of the MVC Step by Step article.


In day 2 we will look in do the following 4 labs.

• Writing unit tests on MVC projects.
• Configure MVC routings.
• Validating MVC routes.
• Configure MVC outbound routes.

In case you are completely a fresher I will suggest to start with the below 4 videos which are 10 minutes approximately so that you can come to MVC quickly.
 

Lab No.

Lab description

Youtube Video demonstration for the same
1 A simple Hello world ASP.NET MVC application. http://youtu.be/KAKxm4eQP24?hd=1
2 In this Lab we will see how we can share data between controller and the view using view data. http://youtu.be/Fu9v2MIDlTA?hd=1
3 In this lab we will create a simple customer model, flourish the same with some data and display the same in a view. http://youtu.be/0-UdqWy9lVc?hd=1 
4 In this lab we will create a simple customer data entry screen with some validation on the view. http://youtu.be/1dlxtHuRw34?hd=1 


So let’s start with the above 4 labs one by one.

Lab 6:- Unit test MVC projects

When we started this whole MVC series (Day 1) we started with two concerns regarding behind code:-


• How can we do unit testing on the ASP.NET behind code?
• How can we reuse the ASP.NET behind code with different user interfaces?

In this section let’s concentrate on the first point i.e. Unit testing.

Just a quick recap if we need to unit test the below method “btngenerateinvoices_click” in ASP.NET behind code , we have the following problems :-

• How do we create the sender and eventargs object?
• The below complete code runs under HttpContext object, how do I mimic them?
• What about ASP.NET UI controls , how do I access them ?
• What about other ASP.NET object like session object, application, how do I access them?.

FYI: - Many developers would talk about mock test, rhino mocks etc but still its cryptic and the complication increases with session variables, view data objects, ASP.NET UI controls creating further confusion.



So what we will do in this section is we will create a simple MVC application and we will do unit test on the ASP.NET application using VSTS unit test framework.

Step1:- Create the simple display customer screen project

The first step is to create a simple MVC project. We will use the same project which we have discussed in MVC (Model view controller) day 1 LearnMVC.aspx.  So in case you do not have any sample project please create one using the link above.



The controller class at the end of the day is a simple .NET class. For instance if you watch your project code closely, you can easily see the customer controller class as shown below.

public class CustomerController : Controller
{
...
....
public ViewResult DisplayCustomer()
{
Customer objCustomer = new Customer();
objCustomer.Id = 12;
objCustomer.CustomerCode = "1001";
objCustomer.Amount = 90.34;

return View("DisplayCustomer",objCustomer);
}
}

In simple words because this is a simple .NET class we can easily instantiate the class and create automated unit tests for the same. That’s what exactly we are going to do in our next steps.

Step 2:- Add a simple unit test project

Let’s use our VSTS unit test framework to test the controller class. In case you are a complete fresher to VSTS unit testing we would request to see this article to get a hang of unit testing http://www.codeproject.com/KB/cs/VSTSTesting.aspx  . Add a new project to your solution using the test project solution template.



Step 3:- Add appropriate project references

We need to add reference to the MVC application in our unit test project so that we can get hold of the controller class.




Once you add the references you should see the MVC application in your project references as shown in the below figure.




Step 4:- Write the unit test

Once you have added the references open the unit test class i.e. ‘UnitTest1.cs’. In this class create a simple test method called as ‘DisplayCustomer’ which is attributed by ‘TestMethod’ attribute as shown in the below code snippet.

If you see the below code snippet we are creating object of the controller class, invoking the controller action i.e. ‘DisplayCustomer’ and then checking if the view name is ‘DisplayCustomer’. If they are equal that means the test passes or else it fails.

[TestMethod]
public void DisplayCustomer()
{
CustomerController obj = new CustomerController();
var varresult = obj.DisplayCustomer();
Assert.AreEqual("DisplayCustomer", varresult.ViewName);
}


Step 5 :- Finally run the unit test

Once you have written your test case it’s time to run the test case by clicking on test , windows and then clicking test view.




On the test view right click on the test and run the selected test case as shown below.




If everything goes well you should see green color indicating that the test has passed or else you should see a red color with details regarding why the test failed.




So what’s in the next Lab

In the next lab we will discuss about MVC routing. MVC is all about connecting the actions to the controllers and MVC routing helps us to achieve the same. So be ready to get routed in our next tutorial.

Lab 7:- Understanding MVC routing

Introduction

At the end of the day MVC is nothing but URL mapped to controllers and controllers mapped to actions.

For example when a user sends a request URL like www.questpond.com/locateproduct  from the browser, these actions are mapped with MVC controllers and MVC controllers finally invokes those functions.

Below is a simple table which shows how the whole thing looks like.



Adding further to the complication we can have multiple URL’s mapped to one controller or you can have more than one controller mapped to a single URL. For instance you can have www.questpond.com/contactus  and www.questpond.com/aboutus  mapped to a single controller called as “AboutUsController”.



It would be great if we have some kind of mechanism by which we can configure these mappings. That’s what exactly MVC routing is meant for. MVC routing helps to easily configure and map the URL with the controllers.




Step 1:- Take the MVC project created in Day 1.

Let’s take the same customer project we had discussed in the previous section.

Step 2 :- Change global.asax.cs

All route mappings are stored in the “global.asax.cs” behind code file. So the first step is we need to go and change this file.



All routing mapping are stored in to a collection called as ‘routes’. This collection belongs to the namespace “System.Web.Routing”. To add a route you need to call the ‘MapRoute’ method and pass three parameters “name”,”url” and “defaults”.

Below is a print screen of the snippet of the ‘maproute’ function.



“Name” is the key name by which the route will be identified from the collection.

“Url” defines what kind of URL format we want to connect with the controllers. For instance in the below code snippet we are saying that “View/ViewCustomer” is the URL format.

“Defaults” defines the controller class and action functions which will be invoked when the URL is called. For instance in the below code we are saying that when “View/ViewCustomer” is called it will invoke the “Customer” controller class and the action function invoked will be “DisplayCustomer”.

In case your controller takes parameters you can use the “{“brackets. For instance in the below code snippet we have used “{“to specify that we can have “id” parameter.

If you want to define the parameter as optional you can use the “UrlParameter.Optional” enum.

The first thing is comment the default mapping code. We will explain the default mapping code later.

//routes.MapRoute(
// "Default", // Route name
// "{controller}/{action}/{id}", // URL with parameters
// new { controller = "Home", action = "Index", id = 
UrlParameter.Optional }); // Parameter defaults

Put the below code , which means when we call http://localhost/View/ViewCustomer/  it will invoke the customer controller and will call displaycustomer function.

routes.MapRoute(
"View", // Route name
"View/ViewCustomer/{id}", // URL with parameters
new { controller = "Customer", action = "DisplayCustomer", 
id = UrlParameter.Optional }); // Parameter defaults


Below is the action function “DisplayCustomer” which will be invoked.

public ViewResult DisplayCustomer()
{
Customer objCustomer = new Customer();
objCustomer.Id = 12;
objCustomer.CustomerCode = "1001";
objCustomer.Amount = 90.34;

return View("DisplayCustomer",objCustomer);
}


Step 3:- Run the application

If you run the application you should see the below display.




If you remember we commented the default entry route. Let’s understand what exactly this default code meant.

"{controller}/{action}/{id}" defines that URL will be automatically named with the convention of controller name / function action name / value. So if you have a controller class with ‘Customer” and action function as “Search” then the URL will be structured as http://xyz.com/Customer/Search  automatically.

//routes.MapRoute(
// "Default", // Route name
// "{controller}/{action}/{id}", // URL with parameters
// new { controller = "Home", action = "Index", id = 
UrlParameter.Optional }); // Parameter defaults

So what’s in the next Lab

In the next lab we will discuss how to validate MVC URL. All actions to MVC come via MVC URL and even data is fed via MVC URL. So in the next section we will see how we can validate the data passed in the MVC URL.

Lab 8:- Validating and setting default values to MVC URLS

MVC is all about action which happens via URL and data for those actions is also provided by the URL. It would be great if we can validate data which is passed via these MVC URL’s.

For instance let’s consider the MVC URL http://localhost/Customer/ViewCustomer  . If anyone wants to view customer details for 1001 customer code he needs to enter http://localhost/Customer/ViewCustomer/1001 .

The customer code is numeric in nature. In other words anyone entering a MVC URL like http://localhost/Customer/ViewCustomer/Shiv  is invalid. MVC framework provides a validation mechanism by which we can check on the URL itself if the data is appropriate. In this lab we will see how to validate data which is entered on the MVC URL.

Step 1:- Create a simple customer model

The first is to create a simple customer class model which will be invoked by the controller.

public class Customer
{
public int Id { set; get; }
public string CustomerCode { set; get; }
public double Amount { set; get; }
}

Step 2:- Create the controller class

The next step is to create a simple controller class which has collection of the customer model object which was created in step 1.

public class CustomerController : Controller
{
List<Customer> Customers = new List<Customer>();
//
// GET: /Customer/
public CustomerController()
{
Customer obj1 = new Customer();
obj1.Id = 12;
obj1.CustomerCode = "1001";
obj1.Amount = 90.34;

Customers.Add(obj1);

obj1 = new Customer();
obj1.Id = 11;
obj1.CustomerCode = "1002";
obj1.Amount = 91;
Customers.Add(obj1);

}

[HttpGet]
public ViewResult DisplayCustomer(int id)
{
Customer objCustomer = Customers[id];

return View("DisplayCustomer",objCustomer);
}
}


The controller has a simple ‘DisplayCustomer’ function which displays the customer using the ‘id’ value. This function takes the ‘id’ value and looks up through the customer collection. Below is the downsized reposted code of the function.

[HttpGet]
public ViewResult DisplayCustomer(int id)
{
Customer objCustomer = Customers[id];

return View("DisplayCustomer",objCustomer);
}

If you look at the ‘DisplayCustomer’ function it takes an ‘id’ value which is numeric. We would like put a validation on this id field with the following constraints:-

• Id should always be numeric.
• It should be between 0 to 99.

We want the above validations to fire when the MVC URL is invoked with data.

Step 3:- Apply validation using regex on the MVC routes

The validation described in the step 2 can be achieved by applying regular expression on the route map. If you go to global.asax file and see the maproute function on the inputs to this function is the constraint as shown in the below figure.



In case you are new to regular expression we would advise you to go through this video on regular expressions http://youtu.be/C2zm0roE-Uc?hd=1

So in order to accommodate the numeric validation we need to the specify the regex constraint i.e. ‘\d{1,2}’ in the ‘maproute’ function as shown below. ‘\d{1,2}’ in regex means that the input should be numeric and should be maximum of length 1 or 2 , i.e. between 0 to 99.

You can specify default values by saying id=0 as shown in the below code snippet. So just in case if some one does not specify the value to the id it will take the value as zero by default.

routes.MapRoute(
"View", // Route name
"View/ViewCustomer/{id}", // URL with parameters
new { controller = "Customer", action = "DisplayCustomer", 
id = 0 }, new { id = @"\d{1,2}" }); // Parameter defaults


Step 4:- Test if it works

So now that we are done with the validation using the ‘maproute’ functions, it’s time to test if these validations work.

So in the first test we have specified valid 1 and we see that the controller is hit and the data is displayed.



If you try to specify value more than 100 you would get error as shown below. Please note that the error is confusing but it’s the effect of the regex validation which is specified on the maproute function.



If you try to specify a non-numeric value you should again get the same error which confirms that our regex validation is working properly.




The most important point to note is that these validations are executed even before the request reaches the controller functions.

So what’s in the next lab

One of the crucial things in any website development is defining navigations from one page to the other page. In MVC everything is an action and those actions invoke the views or pages. We can not specify direct hyperlinks like www.questpond.com/home.aspx  , this would defeat the purpose of MVC. In other words we need to specify actions and these actions will invoke the URL’s.

In the next lab we will look in to how to define outbound URL in MVC views which will help us to navigate from one page to other page.

Lab 9:- Understanding MVC outbound URLs

Introduction

When we talk about web applications end users would like to navigate from one page to other page. So as a simple developer your first thought would be to just give page names as shown in the below figure.

So for example if you want to go and browse from home.aspx to about.aspx give the anchor hyper link page name and things should be fine.

By doing that you are violating MVC principles. MVC principle says that hit should first come to the controller but by specifying <a href=”Home.aspx”> the first hit comes to the view. This bypasses your controller logic completely and your MVC architecture falls flat.




Ideally the actions should direct which page should be invoked. So the hyperlink should have actions in the anchor tags and not the page names i.e. direct view name.

Step 1:- Create views

Lets create three views as shown in the below figure “Home”,”About” and “Product”.




Let’s create a simple navigation between these 3 pages as shown below. From the home view we would like to navigate to about and product view. From about and product view we would like to navigate back to the home view.


Step 2 :- Create controller for the views

Next step is to define controller actions which will invoke these views. In the below code snippet we have defined 3 actions “GotoHome” (this invokes home view), “Aboutus” ( this invokes the about view) and “SeeProduct” ( this invokes product view).

public class SiteController : Controller
{
//
// GET: /Site/

public ActionResult GotoHome()
{
return View("Home");
}

public ActionResult AboutUs()
{
return View("About");
}

public ActionResult SeeProduct()
{
return View("Product");
}
}

Step 3:- Provide actions in the link

To invoke the actions rather than the views we need to specify the actions in the anchor tag as shown in the below code snippet.

This is products
<a href="GotoHome">Go Home</a><br />
<a href="Aboutus">About us</a><br />

If you want to create the anchor links using the HTML helper classes you can use the action link function as shown in the below code snippet.

<%= Html.ActionLink("Home","Gotohome") %>

The above code was for the products page , you can do the same type of navigations for the about us and the home page.

This is About us
<a href="GotoHome">Go Home</a><br />
<a href="SeeProduct">See Product</a><br />

This is home page
<br />
<a href="SeeProduct">See Product</a><br />
<a href="Aboutus">About us</a><br />
</div>

Step 4:- Enjoy your navigation

Once you have specified the actions inside the link you navigate between home, about and products page.




While navigating you can see how the URL’s are pointing to the actions rather than absolute page names like home.aspx, aboutus.aspx etc which violates the complete MVC principle.

What’s for third day?

Will update this section in a day or 2 , hope for  the co-operation.

Final note you can watch my .NET interview questions and answers videos on various sections like WCF, Silver light, LINQ, WPF, Design patterns, Entity framework etc.

 

License

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

About the Author

Shivprasad koirala
Architect http://www.questpond.com
India India
Member

I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small
E-learning company in India. We are very much active in making training videos ,
writing books and corporate trainings. Do visit my site for 
.NET, C# , design pattern , WCF , Silverlight
, LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server  training 
and Interview questions and answers


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionI do not know how to swim.membervikas.gupta115 Apr '13 - 18:31 
Hi Shivprasad,
 
Please do not leave our boat in between. We are eagerly waiting for days 4,5,6,7.
 
Thanks
Vikas Gupta
QuestionDay two - future?memberdonluz14 Apr '13 - 16:19 
Got excited about this and got to the end of Day 2 and that was it... for nearly a year now. Unfortunate for us at the other end Frown | :-(
AnswerRe: Day two - future?mvpShivprasad koirala14 Apr '13 - 16:22 
Please continue reading Learn MVC (Model View Controller) Step by Step in 7 Days – Day 3[^]
My book .NET interview questions with 500 mostly asked questions in .NET world .NET Interview questions and answers

Questionwhere i found third day code screenmemberRaghvendra Singh Verma11 Apr '13 - 23:29 
where i found third day code screen
AnswerRe: where i found third day code screenmvpShivprasad koirala12 Apr '13 - 0:53 
You mean where is the 3rd day , below is the link
Learn MVC (Model View Controller) Step by Step in 7 Days – Day 3[^]
My book .NET interview questions with 500 mostly asked questions in .NET world .NET Interview questions and answers

GeneralMy vote of 5memberIgnacio Guillen29 Mar '13 - 21:49 
Excelent explication about MVC model
GeneralMy vote of 5memberbalabkn14 Mar '13 - 1:04 
superb
GeneralMy vote of 5memberbensonissac4 Mar '13 - 0:31 
helped to study and understand MVC
GeneralLearn MVC (Model view controller) Step by Step in 7 days – Day 1memberrahevika22 Feb '13 - 21:20 
nice topic thank you ....
QuestionProduct or SeeProductmemberOrionGG20 Jan '13 - 11:32 
I think you must replace:
return View("Product");
by
return View("SeeProduct");
 
Don't you?
GeneralRemaining days pleasememberHunny Tomar17 Dec '12 - 21:31 
good for beginners.. please share remaining parts.
QuestionExcellent Article...memberVisPriya20 Nov '12 - 20:47 
Excellent Article that i had never come across... and its very useful for beginners... Thanks a lot...
Questionawesome article for the beginer.membersumitmishra4829 Oct '12 - 15:40 
This article is awesome for the beginer and it give the step by step guide to learn the MVC
 
Thank you so much !!!!!!!!!!!!!!!!!!!!!
Smile | :) Smile | :) Smile | :) Smile | :)
QuestionWhere can I find Day 3 article.memberMember 82766914 Oct '12 - 3:26 
Congratulation and thanks for writing nice article, please tell me where I can find day 3 article.
thanks
AnswerRe: Where can I find Day 3 article.memberShivprasad koirala4 Oct '12 - 3:35 
Here you go
Learn MVC (Model View Controller) Step by Step in 7 Days – Day 3[^]
My book .NET interview questions with 500 mostly asked questions in .NET world .NET Interview questions and answers

GeneralMy vote of 3memberMember 94097052 Oct '12 - 3:20 
Needed to add
 
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
); // Parameter defaults
 
to global.asax.cs to make navigation work. This should be mentioned.
QuestionVery nicely done.memberMember 238651124 Sep '12 - 10:45 
I was excited to read the whole article. Thanks for spreading the knowledge.
 
Thanks very much.
GeneralMy vote of 5memberSRR268 Jul '12 - 1:42 
Great Article
GeneralMy vote of 5membermanoj kumar choubey30 May '12 - 21:02 
Nice
SuggestionNice tutorial I have ever seen!memberLam pat13 May '12 - 16:44 
A great tutorial with videos! And I would like to see more new videos on youtube, thanks a lot!
GeneralMy vote of 5memberaditya_bhushan8 May '12 - 1:45 
thanks
GeneralMy vote of 3memberdhunju1 May '12 - 7:28 
Issues with the Lab
Questionwhere can I find Day 3memberramireddykr12 Apr '12 - 3:24 
please can you get me the third day class
AnswerRe: where can I find Day 3memberShivprasad koirala28 Apr '12 - 9:22 
its there in the article.
My book .NET interview questions with 500 mostly asked questions in .NET world .NET Interview questions and answers

GeneralRe: where can I find Day 3memberDeighvan12 Jun '12 - 4:38 
This was a sales pitch? I feel cheated...
 
EDIT: My apologies. Found the link here from the first page...
 
Day 3:
Learn MVC (Model view controller) Step by Step in 7days – Day 3[^]
GeneralRe: where can I find Day 3memberShivprasad koirala12 Jun '12 - 7:37 
I try to add 1 article in every 2 weeks , So please excuse for the same.
My book .NET interview questions with 500 mostly asked questions in .NET world .NET Interview questions and answers

GeneralRe: where can I find Day 3memberDeighvan12 Jun '12 - 8:57 
I think I was confused by your signature.
 
Your tutorials are amazing by the way. Thanks!
GeneralMy vote of 5memberRaman Ghantiyala27 Mar '12 - 2:50 
Nice Article for Mvc beginner
QuestionNext Articles?memberbhaiwal15 Mar '12 - 21:21 
When can we expect next articles?
Man

QuestionMVCmemberPravin4knowledge14 Mar '12 - 20:24 
This Article is very useful to me. I hope the remaining sessions will be uploaded soon. My humble Request is to plz upload it with the video tutorials. Thank you..
Questionvery nicememberPurushottam Prajapati1 Mar '12 - 23:07 
i didn't find article 3 and onwards , can u publish that
QuestionWhy did you not use Razor (.cshtml) instead of (.aspx) for your Views?membersobo12318 Feb '12 - 21:30 
Why did you not use Razor (.cshtml) instead of (.aspx) for your Views?
AnswerRe: Why did you not use Razor (.cshtml) instead of (.aspx) for your Views?memberShivprasad koirala28 Apr '12 - 9:21 
In my day 3 i have already used razor.
My book .NET interview questions with 500 mostly asked questions in .NET world .NET Interview questions and answers

QuestionA simple way to Learn MVCmemberRahul Dhamale31 Jan '12 - 23:54 
Hi,
 
Really helpful for beginners. Waiting for the article number 3rd and onwards.
 
Thanks
Rahul
GeneralMy vote of 5memberharveenk17 Jan '12 - 23:01 
Excellent Artical. I was waiting for this kind of Artical. Now waiting for Third Artical.
QuestionDay 3 PleasememberK.JaganMohan Reddy9 Jan '12 - 0:25 
Day 3 Please
QuestionWhere is Day 3memberAzhar Iqbal SE21 Dec '11 - 20:39 
Nice effort by Shivprasad koirala
I am not getting Material of Day 3 and onward. Where should I get that one.
Thanks
Questionwhere's day 3? 4-7?memberbebangs14 Dec '11 - 20:14 
it's been almost 3 months... Confused | :confused:
QuestionNice Articlememberyeahgrp12 Oct '11 - 6:19 
Mr. Koirala, its about half a month gone for the submission
still day 3 is not their
QuestionLab 6 does not work for mememberTAN THIAM HUAT9 Oct '11 - 16:50 
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MyFirstHelloWorld.Controllers;
 
namespace TestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void DisplayCustomer()
        {
            CustomerController obj = new CustomerController();
            var varresult = obj.DisplayCustomer();
            Assert.AreEqual("DisplayCustomer", varresult);
        }
    }
}
 

I can only have
Assert.AreEqual("DisplayCustomer", varresult);
 
not
Assert.AreEqual("DisplayCustomer", varresult.ViewName);
 
then it can be compiled. But Run Selection test show this:
Failed DisplayCustomer TestProject1 Test method TestProject1.UnitTest1.DisplayCustomer threw exception:
...
AnswerRe: Lab 6 does not work for mememberLovinBill4 May '12 - 5:52 
Same for me....
GeneralRe: Lab 6 does not work for mememberhollysong20 Jun '12 - 4:08 
Check the type of the object. May can be dynamic...
AnswerRe: Lab 6 does not work for memembervdrunen29 Jun '12 - 2:23 
That is because DisplayController() is defined in these examples to return an ActionResult. ViewName however is a property of the ViewResult class (which is inherited from ActionResult). Since the real object returned by DisplayController() is a ViewResult you can simply cast varresult to ViewResult and then it should work.
GeneralMy vote of 4memberlogicalweb5 Oct '11 - 0:58 
Article are really very nice. Waitting for 3rd article.
GeneralRegarding third ChaptermemberPro_kk28 Sep '11 - 18:43 
Sir,
 
I have read the chapter 1 & 2, and it was helpful and learning article. i am waiting for the third chapter. So please post the chapter so that it will help me to learn the concept of MVC. thanx
QuestionLearn MVC (Model view controller) Step by Step in 7 days – Day 1 & 2membercdvaghela28 Sep '11 - 0:46 
Hello Sir,
 

I am go through both article.
 
Its reallly very very   nice article.
 
I m waitting for 3rd article. When it's release.
 
Pls reply.
QuestionLab7 Doesn't Workmembercjb11026 Sep '11 - 2:31 
I can't get the routing lab to work. I keep getting "Resource Not found" errors.
 
routes.MapRoute(
    "View",
    "View/ViewCustomer/{id}",
    new { controller = "Customer", action = "DisplayCustomer", id = UrlParameter.Optional });

AnswerRe: Lab7 Doesn't Workmemberstambo29 Sep '11 - 5:31 
It works for me when I change it to:
 
RouteTable.Routes.MapRoute(
"View",
"View/ViewCustomer/{id}",
new { controller = "Customer", action = "DisplayCustomer", id = UrlParameter.Optional }
GeneralRe: Lab7 Doesn't WorkmemberMember 94097052 Oct '12 - 3:10 
Make sure you have the default route in your global.asax.cs file:
 
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new
{
controller = "Home",
action = "Index",
id =
UrlParameter.Optional
}); // Parameter defaults
 
Then invoke
 
http://localhost:5413/Site/GoHome
 
in your browser (make sure you adjust the port number to the one your ASP.NET Development Server is using).
GeneralMy vote of 5membersujit076126 Sep '11 - 0:22 
My vote of 5, for this easy to understand article.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 28 Apr 2012
Article Copyright 2011 by Shivprasad koirala
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid