TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

ASP.Net MVC View

ASP.Net MVC View with asp.net tutorial, asp.net introduction, features, project, example, server controls, labels, textbox, button, hyperlink, radiobutton, calender, checkbox, fileupload, events handling, authentication, webforms model binding, html server control, compare validdator, range validator, validation summary, mvc introduction, mvc project, view, validation, entity framework, authentication etc.

<< Back to ASP

ASP.NET MVC View

The MVC View is a standard HTML page that may contain script. It is used to create web pages for the application. Unlike ASP.NET Web Pages, MVC Views are mapped to the action and then controller renders the view to the browser.

MVC has certain conventions for project structure. The view file should be located in the subdirectory of View folder.

MVC uses Razor view engine so that we can write server side code in HTML as well. Let's create a view and execute it to the browser.


Creating View to the Application

To add view, right click on the subfolder inside the View folder and select Add-> Add View. It will pop up for the view name etc.

ASP View 1

This file has following default code.

// Welcome.cshtml

@{
    ViewBag.Title = "Welcome";
}
<h2>Welcome</h2>

If we want to execute it, we have a controller like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplicationDemo.Controllers
{
    public class StudentsController : Controller
    {
        // GET: Students
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Welcome()
        {
            return View();
        }
    }
}

This controller has Welcome action method that will render Welcome view file to the browser. Right click on the Welcome.cshtml file and select view in browser. This will produce the following output.

Output:

ASP View 2




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf