Wednesday, December 21, 2016

Getting Started With Asp.Net Mvc

Creating your first Asp.Net Mvc application

  1. Visual Studio Open.
  2. Click File => New Project.
  3. Select Web and Select Asp.Net MVC 4 application.
  4. Write Name => MyFirstMVCApplication and Click OK.
    MyFirstMVCApplication
    MyFirstMVCApplication
  5. Select Empty template and View Engine as Razor and click OK.
    MyFirstMVCApplication
    Empty template
Visual Studio Created Asp.Net Mvc application.

Now, than after add Controller to your project.
  1. Right click Controllers Folder in our project  and Select => Add => Controller.
    ControllerImage
    Controller
  2. And Set Name HomeController and click Add.
    HomeControllerImages
    HomeControllerImage
Now, This will created class file HomeController.cs under controllersfolder.


using System;
using System.Web.Mvc;

namespace MyFirstMVCApplication.Controllers
{
    public class HomeController : Controller
    {
     public ViewResult Index()
        {

            return View();
         }   
     }
}

Now , We add new View  to our Home Controller to add new view , right click on View folder and click Add => View.
Views
View

First we write name is Index and  View engine select Razor(CSHTML) and  click OK.
Indexs
Index

New CSHTML file inside View/Home folder with the following code.

@{
    Layout = null;
    }

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
    
    </div>
</body>
</html>

Now , Modify  above View  body content with the following code.

<body>
    <div>
     Welcome to My First MVC Application.
    </div>
</body>

Now , Run apllication 

Get OUTPUT
webpageviewimage
OutPut







No comments:

Post a Comment