ASP.NET MVC Introduction, Create First Applicatio using MVC

0
ASP.NET MVC Introduction:-
......................................................................................................................................................................

it is used to create a dynamic web application using the MVC Design patterns.

MVC means Model, View, and Controller

Model ----> Data Access Layer

View ----> Designing

Controller ---> logic

MVC Provide distributed project structure for a large web application.

it provides better performance and security as compared to ASP.NET Classic Web Application. ASP.NET Classic has server-side controls which take more time to process data.

Install visual studio,

File ----- >  New ----> Project---> Select Web from Left Side bar ----->  ASP.NET MVC4 Web Application ---->  Empty


Step1st:-

Create Controller


 public class HelloController : Controller
    {
        //
        // GET: /Hello/

        public ActionResult Index()
        {
            return View();
        }

    }

Step2nd:-

Create View:-

Right-click on the controller method and select add view menu option then it will create html file
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
        <h1>Welcome in ASP.NET MVC Web Application</h1>
    </div>
</body>
</html>


Step3rd:-


APP_Start->RouteConfig.Cs--> Controllername ---> Methodname
  routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );



Now I am providing another example to create an Addition Program then.


1)  create controller under right-click on controller folder.

public class AdditionController : Controller
    {
        //
        // GET: /Addition/

        public ActionResult Index()
        {
            int a = 100, b = 200, c;
            c=a+b;
            ViewBag.data = "Result is " + c;
            return View();
        }

    }

2)  create view and write viewdatta object

@{
    Layout = null;
}

<!DOCTYPE html>

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







Tags

Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)