1.

Explain how to create an ASP.NET MVC project with source code.

Answer»

The following steps will explain how to create an ASP.NET MVC-based web application using Visual Studio 2019 IDE.

Creating a Web Project: Open the Visual Studio and click on the menu bar, then select the new option for creating a new project. You can see how to create a new project in the below-given image:

Select Project Type: Select the project type as an ASP.NET Web Application(.NET framework) and click on the Next button.

Provide Project Name: The name of the project should be provided in the following window and then click on Create button.

Select MVC Template: Now, select the MVC web template from the list of templates available, as we are implementing the MVC project. Then click on Create.

MVC Web Application Project Structure: The following image represents the project structure of the project created by us.

You can see that the Project structure is having three folders namely Model, View, and Controller. The default controller for the created application is the HomeController. By default, the HomeController consists of the following code:

// HomeController.vbPublic CLASS HomeController Inherits System.Web.Mvc.Controller Function Index() As ActionResult Return View() End Function Function About() As ActionResult ViewData("Message") = "Your application description page." Return View() End Function Function Contact() As ActionResult ViewData("Message") = "Your contact page." Return View() End FunctionEnd Class

The Index file in the views folder will be the default file for the home controller.

// index.vbhtml@Code ViewData("Title") = "Home Page"End Code<div class="jumbotron"> <H1>ASP.NET</h1> <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p> <p><a href="https://asp.net" class="btn btn-primary btn-lg">Learn more »</a></p></div><div class="row"> <div class="col-md-4"> <h2>Getting started</h2> <p> ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that enables a clean separation of concerns and gives you full control over markup for enjoyable, agile development. </p> <p><a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301865">Learn more »</a></p> </div> <div class="col-md-4"> <h2>Get more libraries</h2> <p>NuGet is a free Visual Studio extension that MAKES it easy to add, remove, and update libraries and tools in Visual Studio projects.</p> <p><a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301866">Learn more »</a></p> </div> <div class="col-md-4"> <h2>Web Hosting</h2> <p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p> <p><a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301867">Learn more »</a></p> </div></div>

The above default code in the project will produce the below-given output when it is viewed in the BROWSER:

Conclusion

The MVC pattern of ASP.NET has various advantages because of the separation between business logic, input logic, and user interface(UI) logic. But it has a few drawbacks such as it is completely controlled by JavaScript, HTML, and CSS, also it cannot be easily learned without any experiments.

To become industry competent, apart from learning the ASP.NET MVC, one must learn the commonly used C# programming language, SQL Server, OOPs, and some of the front-end technologies such as JavaScript, HTML, JQuery, etc.

Useful Interview Resources:

  • .NET Interview Questions
  • OOPs Interview Questions
  • C# Interview Questions
  • SQL Interview Questions


Discussion

No Comment Found