View is an ASPX page without having a code behind file. All page specific HTML generation and formatting can be done inside view. We can use inline code (server tags) to develop dynamic pages. A request to view (ASPX page) can be made only from a controller’s action method.
It is recommended that before creating View add Controller and Model in an application but it’s not compulsory.
We can add View in an MVC application:
Right click Home folder that is nested with in the View folder Select Add Select View.
When you select View option, Add View dialog box will open.
1) Give the View Name as you created in a HomeController or give Index() if nothing is provided.
2) Here we create our view as a strongly-typed view, therefore check Create a strongly- typed view option and add a Model class from the Dropdown list in a View. Strongly typed view is created when we want to use the functionality of particular model. If we select normal view then we cannot use the functionality of model. In that case, we can use Controller properties (ViewData, ViewBag and TemplateData) to send the dynamic data in that view.
3) Click on Add button to add a view successfully.
Write some part of code in view as written below, so you can identify view page easily.
<h2>This is my First View Page</h2>
After creating a view, also create a Controller class in order to run an application.
public class HomeController : Controller
// GET: /Home/
public ActionResult Index()
A view is a standard (X)HTML document that can contain scripts. You use scripts to add dynamic content to a view.
You use the script delimiters <% and %> to mark the beginning and end of a script. This script is written in C#. It displays the current date and time by calling the Response.Write() method to render content to the browser. The script delimiters <% and %> can be used to execute one or more statements.
The current date and time is
You can use HTML Helpers to generate standard HTML elements such as textboxes, links, dropdown lists, and list boxes.
All of the HTML Helpers methods are called on the Html property of the view. For example, you render a TextBox by calling the Html.TextBox() method.
<label for="UserID">User ID :</label>
<%= Html.TextBox("UserID") %>