how to create controller in mvc

20 March

To remove the 404 Not Found error, we need to add a controller, which handles all the incoming requests.

Step 1 − To add a controller, right-click on the controller folder in the solution explorer and select Add Controller.

how to create controller in mvc
Step 2 −  Select the MVC 5 Controller – Empty option and click ‘Add’ button.

The Add Controller dialog will appear


how to create controller in mvc



Step 3 − Set the name to FirstMVCController and click the Add button.

You will see a new C# file FirstMVCController.cs in the Controllers folder, which is open for editing in Visual Studio as well.


how to create controller in mvc

Step 4 − To make this a working example, let’s modify the controller class by changing the action method called Index using the following code. 

public class FirstMVCController : Controller  

{     //  GET:    FirstMVC   

public string Index() {            

            return "Hello World, this is ASP.Net MVC Tutorials";   

   }    

Step 5 − Run this application and you will see that the browser is displaying the result of the Index action method

No comments:

Powered by Blogger.