C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
ASP.NET MVC ViewThe 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 ApplicationTo 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. 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:
Next TopicASP.NET MVC Validation
|