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:

@Scripts.Render("~/Scripts/cart/js")
@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.

15 comments:

  1. Great, useful.

    I found another great article describing new features of ASP.NET MVC 4 in form of interview questions.
    http://jinaldesai.net/asp-net-mvc-4-new-features-interview-questions/

    HTH!

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

    http://www.webdevelopmenthelp.net/2013/09/Top-ASP-NET-MVC-Interview-Questions.html

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

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

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Very useful,but very less in number.Expecting more questions....

    C# Tutorials

    ReplyDelete
  7. Hiya,


    I love all the posts, I really enjoyed.
    I would like more information about this, because it is very nice., Thanks for sharing.



    I was wondering what's a good library or some code to find the similarities between one image and another image/images. I have some software I'm writing where the user has a set of images and he/she wants to compare one image to the rest and then output the similarities into an image file
    to visually see the differences. I've used code before to do very simple compares but they're not detailed enough and I have no clue how to output the similarities or differences into and image file. Does anyone have any ideas?





    I am so grateful for your blog. Really looking forward to read more.


    Kind Regards,
    Irene Hynes

    ReplyDelete
  8. Some time all you have to do is arrange some Good quality office chairs from top brands to make your home office look really awesome and fantastic. Adding a good office vibe is really important trust me.

    ReplyDelete
  9. Here in this article we ;re sharing with you the step by step guide on how to install the printer that hp printer printing blank pages. The steps would be easy to follow.

    ReplyDelete
  10. Really infomational and educative article thanks publisher for sharing this wonderful info i have shared this article on my blog tecktak flippzilla
    and whatsaup, and Best smart tv

    ReplyDelete