Z 6 ) MVC Razor


 Razor

Controller :-

 using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;


namespace WebApplication1.Controllers

{

    public class StudentController : Controller

    {

        // GET: Student

        public ActionResult Index()

        {

            return View();

        }

    }

}


Model :- 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;


namespace WebApplication1.Models

{

    public class Stud

    {

    }

}


View :-(empty , No use Layout )

@model WebApplication1.Models.Stud


@{

    var h1 = "This is a Razor Application";

}


<h1>@h1</h1>     // Call using @


Razor View Engine Interview Questions Answers

1. What is Razor View Engine ?

:- Razor View Engine is a markup syntax which helps us to write HTML and server-side code in web pages using C# or VB.Net. It is server-side markup language however it is not at all a programming language. 


2. What are the Advantages of  Razor View Engine ?

⦁ It is Compact, Expressive, and Fluid. Razor helps us to minimize the coding and provide us a fast and fluid coding work flow.

⦁ Easy to Learn: Razor is easy to learn. We can also use our existing HTML skills.

⦁ The parser (available with Razor) is smart enough. It is also able to decide at run time what is a code element and what is a content element.

   For example, in the following code the @ character is also part of an email address, but Razor is smart enough to identify which is code and which is static content.

<p>  

        please contact to abc@gmail.com to more information  

       Current Date time : @DateTime.Now  

</p>


⦁ Razor is not a new language but it is markup so that we can also use Razor with any language like C# and VB.

⦁ Razor also supports the concept of layout pages (the same as Master Pages in ASPX View Engine), that allows us to define a common site template, in other words a common look and feel across all the pages within a web site/application.

⦁ Razor does not require any special tool to write markup. We can also write our markup code with any old plain text editor like Notepad.

⦁ The Razor View Engine is designed such that it also supports unit test views without requiring a controller and web server. This can be hosted in any unit project. There is no special application domain required.

⦁ The Razor View Engine is designed such that it also supports unit test views without requiring a controller and web server. This can be hosted in any unit project. There is no special application domain required.

⦁ ASP.NET MVC has HTML helpers that are methods that can be invoked within a code block. All existing HTML extension methods can be used with a Razor View Engine without any code changes.

⦁ The code looks clean.

⦁ Powerful built-in validation of markup that helps us to avoid unwanted runtime exceptions due to errors in the view.

⦁ The Razor View Engine has the section concept that is equivalent to content placeholders in the ASPX View Engine and that can be optional.

⦁ The @model directive provides a cleaner and more concise way to define a strongly typed model.


3. In which part of the Asp.net MVC Page life cycle , Razor engine will be used ?

Razor kicks in at Execute result in asp.net MVC Page life cycle.


4. What is the file extension of Razor view engine ?

:- Files containing Razor generally have a . cshtml file extension.


5. What Template does Razor view engine uses ?

:- Instead of MasterPages for the template, Razor uses Layouts.


6. How to add Namespaces in Razor view engine?

:- @using YourCustomNamespace

Eg : @using  EmployeeNamespace


7. How Variables are declared in Razor View Engine ?

:- Variables are declared with the var keywords.


8. How inline expressions are declared in Razor View Engine?

:- All the inline expressions like variables and functions start with @.

Eg: <li @Html.Css("selected", Model.Mode == "map" )>STUFF</li>


9. What are the Different View engines which can be used in asp.net MVC ?

:- Asp.net supports different view engines apart from Razor and Asp.net View Engine.


Comments

Popular posts from this blog

Z 7) ViewData__ViewBag__TempData__Session

Z 8 ) MVC HTMLHELPER METHOD AND ACTIONLINK (how to use css ,atrributes,style in css)

Z 5 ) MVC (Model view Controller)