Posts

Showing posts from 2018

How to Add Controller in MVC

Image
There are two approaches to add the controller in the ASP.NET MVC. Approach-1: Using Scaffolding method. Right Click on Controller Folder Select Add -> Controller  Following picture shows the controller template selected. Click Add button Name the controller as given image Click on the Add button and that all the controller will generate in the Controller Folder as given bellowed Image Approach - 2: By adding a normal class Right Click on Controller folder  Select Add Class or New Item Import the namespace using System.Web.Mvc; Inherit the class name Controller in it. And thats all the controller is ready.

Creating the new MVC project in visual studio and using View Data

Image
Creating the new MVC project in Visual Studio 2015 Open Visual Studio Goto File -> New -> Project Select Templates-> Visual C#-> Web -> Asp.NET Web Application Give project Name(Any Name you Want, I Used "MvcWebApp") Adding a Controller into the project Goto Solution Explorer -> Right Click On Controller Folder Add-> Controller -> Select MVC5 Controller-Empty(In Add Scaffold Box) Give the name for controller HomeController (Suffix xxController mandatory.)  It will generate following code with one Action Method. Now right click on Action Method And select Add View It will Add Index.cshtml int directory Views/Home/ in Solution Explorer. Now Add some code to Action Method Code for Index.cshtml