Please navigate to the bottom of the page for Table of Contents

Friday, January 11, 2013

Asp.Net MVC interview questions

Asp.Net web UI has come a long way in the last 10 years. Starting for classic ASP world, we are now seeing the evolution of world class product in the form of Asp.Net MVC. Web Forms still work and are great for many specific applications. But MVC is the correct way to go for most internet applications.
In this and future posts, we will go over a few ASP.NET MVC interview questions. Let’s tackle Razor engine in this post.

Question: What is Asp.Net MVC Razor?

Razor is the newest view engine released by Microsoft. It’s key features include optimized Html generation, easy to learn, compact, expressive and enabling a fluid coding workflow. The Razor syntax is a template markup syntax that enables you to use an HTML construction workflow. Instead of using the ASP.NET .ASPX markup syntax with <%= %> symbols to indicate code blocks, Razor syntax starts code blocks with a @ character and does not require explicit closing of the code-block.

Question: How can you create a link to a JavaScript file in a view?
With MVC 4 release, the Razor engine has been updated to better serve files. Instead of having to use path mapping methods @Url.Content to render the content of the file, you can now render using the tilde ( ~ ) character as shown below:
<script src="~/Scripts/ref.js"></script>

Question: Display some content only if a certain property in the backing model is not null.
Many times, you have the situation where you need to change the CSS property for a certain block of text only if the backing model has that info. This relatively common feature can now be simply rendered by direct html binding as shown below:

<div class="@Model.HighlightImClass">@Model.UserIm</div>

Question: How can you set the checked state of input boxes based on backing model?
This is again similar in nature to the question above. You can directly bind boolean properties of the model to Html controls.

<input checked="@Model.IsFreeShipping" type="checkbox" />

Question: How can you use Razor to serve bundled CSS or JavaScript files?
In a nutshell? Very cleanly in an intuitive way. MVC 4 has a brand new syntax to serve bundled content as shown:

@Styles.Render("~/Content/cart/css", "~/Content/order/css")

There are a lot of good resources on the web to learn more about  MVC, Razor and Asp.Net in general. In the next post, we will look at some more complex interview questions on Views of MVC.


  1. Good. Please add more.

  2. Great, useful.

    I found another great article describing new features of ASP.NET MVC 4 in form of interview questions.


  3. Good one.
    For Top 10 ASP.NET MVC Interview Questions, please follow:

  4. Nikhil Sir Please Add Other features like WCF,WPF,SHAREPOINT ETC. //////////////////////////////////////]

    About MVC so much is left behind Please Add with this Page ++++++++++++++++++++++++++)