Introduction:

Here we will explain to what is view in mvc asp.net how many types are available view engine in mvc. How to use view in mvc , syntax of razor view engine and aspx view engine what is different aspx and razor view engine in mvc asp.net with example.

Description:

View is a component of MVC framework . it is used to user interface view generally bind from the model data view have extensions like cshtml,vbhtml. My mvc application we had used views with controller to display data the end user. For rendering these static and dynamic content to the browser, MVC framework utilizes View Engines. View engines are used to finaly rendring the html to browser.

 

The mvc framework provide two type view engine.

1. Razor Engine: Microsoft introduced the Razor view engine and packaged with MVC 3 we can write a mix of html tags and server side code in razor view. Razor uses @ character for server side code instead of traditional <% %>. You can use C# or Visual Basic syntax to write server side code inside razor view. Razor is a markup syntax that enables the server side C# or VB code into web pages. This server side code can be used to create dynamic content when the web page is being loaded. Razor is an advanced engine as compared to ASPX engine.

2. ASPX Engine: ASPX or the Web Forms engine is the default view engine that is included in the MVC Framework since the beginning. Writing code with this engine is very similar to writing code in ASP.NET Web Forms.

Following the code below comparing both Razor and ASPX engine.

Razor:

@Html.ActionLink("Add", "EmployeeAdd")


ASPX:


<% Html.ActionLink("Add", "EmployeeAdd") %>

These View Engines can be coded and implemented in following two types:

1. Strongly typed

2. Dynamic typed

Strongly typed:

The view which bind with model is called as strogly typed view. You can bind any class as model to view.You can access model properties on that view. You can use data associated with model to render controls.

Syntax :

@Html.TextBoxFor(m => m.Title, new { @class = "form-control",@placeholder = "Title" })

Dynamic typed

The view use dynmic model is call dynmic type view .You can bind any class as model to view.You can access model properties on that view for render Content.

Syntax :

@model
dynamic
    @{
        ViewBag.Title = "dynamic";
    }
    <h2> dynamic Typed</h2>
    <p>
        <ul>
            @foreach (var user in Model)
            {
                <li>
                    <a href="#">@user.Name</a>
                </li>
            }
        </ul>
    </p>

I Hope This Article help to you.



0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like