Getting Started with ASP.NET MVC 5

See the following Steps:

Step 1: Create an ASP.Net Project then press the OK button,  then select the template which is known as MVC and check the MVC box, then pressthe OK Button. Now your project is ready.

Now you see the project; there are three folder known as Model, View, and Controller.

select the template

Step 2: Now you add model; left click on your project solution and move to the add items and select the class. At this time you choose MVC 5 Controller Empty, now click on add button. Now you give the name of controller name, remember that by default MVC finds Home Controlle. Now I am giving the name of controller known as HomeController; then pressthe add button. Now you see that the controller contais one ActionResult.

ActionResult

Step 3: Now the method is appeaing, and the name is Index. We change its only return type, which is known as ActionResult. We replaced it from strin;g and in method we delete the view calling and typ, "hello world".

Controller

Step 4: When you run the play button you see the result.

See result
Step 5: You can see that inthe browser address bar http://localhost:53023/ is appeaing. Iif you want to run a particular method you give the name after this address controller name and then method name you just see a particular method, such as make a new method in HomeController the same as Index method and only change the method name and return type.

Code

Step 6: Now when you run the project you givethe default result known as "hello world" but when you type the controller name and method name then you see the particular method like wise

output
Step 7: Then come to the project and see in the project solution the aap_start name folder appears, then click it and after that you see that there is Route.Config file  appears. Click on it nowthat you see that in the line ofthe  url it's first call controller, then action means method, and don’t confuse about the id, because id is a method parameter. And you also see in step two I give the controller name"Home," so you see that by default MVC finds HomeController and index method. And if you want change it to a particular controller and action,  then it will do with your choice, not as default.

Program

Step 8: If we change the action which is known as Index and replace as MyIndex then after running the program we just see the result of Myindex method.

run

Hopefully you understand clearly about model, view, and controller structure in MVC.


Similar Articles