Wednesday, July 20, 2016

ASP.NET MVC Interview Questions and Answers

ASP.NET MVC is getting popular more and more day by day, it has different features, it is popular due to its Modal-View-Controller architecture.
This article contains ASP.NET MVC interview questions that will help you to brush up your asp.net MVC concepts, this is the one point stop where you can get interview breaker Q & A.

Let's go through it

1. What is ASP.NET MVC ?
This is the most common asked question, it is an architectural pattern which separates the UI and code. It's basically divided into Model, View, and Controller section.
- As name suggest, The View is responsible for the look and feel.
- Model is real world object and provides data to the View.
- This is the heart of the architecture, it responsible for request and loading the appropriate Model and View.


2. What are the features of ASP.NET MVC?
- Clear separation of application concerns.
- Supports for Test Driven Development
- Supports Membership and roles, authentication and authorization, provider model and caching

3. What is Routing in ASP.NET MVC?
Routing is very easy in ASP.NET MVC. it shows user friendly URL in application, it is just like a URL rewriting. ASP.NET MVC framework uses a routing engine, that maps URLs to controller classes
see below image in which you can see difference between ASP.NET path and ASP.NET MVC path, We can define routing rules for the engine, so that it can map incoming request URLs to appropriate controller
When URL redirect to another page it collect routing rules that are defined in Global.asax file and process the request

4. How to navigate from One view to another ?
You can easily do it using Hyperlink, by using 'ActionLink' method we can navigate to destination action
see below snippet
<%= Html.ActionLink("Home","GotoDestination") %>

5. What is VIEWDATA in ASP.NET MVC ?
To pass data from controller to view and in next subsequent request, ASP.NET MVC uses VIEWDATA. But it is limited to only server call and to main the state. When i redirect to another page
it gives me 'null' value, it acts between a link in VIEW and CONTROLLER. ViewData being a dictionary object is accessible using strings as keys.
ViewData requires typecasting for complex data type and check for null values to avoid error.
see below sample
//IN CONTROLLER
//add some value to VIEWDATA
public ActionResult Index()
{
 ViewData["Text"] = "This is from view data";
 return View();
}

//IN VIEW
//access it in dictonary
@ViewData["Text"]

6. What is VIEWBAG in ASP.NET MVC ?
It is simply same as VIEWDATA, which used to maintain state and transfer values between controller to view and in next subsequent request, just the difference is ViewBag is a dynamic property that takes advantage of the new dynamic features
ViewBag doesn't require typecasting for complex data type, both VIEWDATA and VIEWBAG has short life means, they are 'null' if redirect to another page
see below sample

//IN CONTROLLER
//add some value to VIEWDATA
public ActionResult Index()
{
 ViewBag.Name = "This is from VIEWBAG";
 return View();
}

//IN VIEW
//access it
@ViewBag.Name 
7. What is TEMPDATA in ASP.NET MVC ?
TEMPDATA is also dictionary type but it access request data and maintain state between multiple redirect, from one controller to the other controller or from one action to other action.
it uses HTTP request to transfer data. It internally uses session variables. it can be used to store only one time messages like exceptions.


see below sample
//in controller 1
public ActionResult Index()
{
 var model = new Review()
 {
 Body = "i am controller 1",
 };
 TempData["CON1"] = model;
 return RedirectToAction("Test");
}

//in controller 2
public ActionResult Test() 
{ 
 var model= TempData["CON1"]; 
 return View(model); 
}
8. How to transfer values in ASP.NET MVC between Controller and View ?
There are following ways to transfer values in ASP.NET MVC
1. ViewData : Transfer values only between Controller to View
2. ViewBag : Transfer values only between Controller to View
3. TempData : Transfer values only between Controller to Controller
4.Session Variables : It is very strong and dynamic way to Transfer values in ASP.NET MVC, it supports values transfer between Controller to Controller, Controller to View and View and Controller
5. Hidden Fields : Transfer values only between View to Controller

9. Is TempData can persist values between multiple request ?
This is very weird question The answer of this question is YES and NO,
YES cause it can persist values between request and NO cause once the value of TempData is read, it is empty

10. What is Model ?
Model is the layer between UI and input, in simple ways it handles all business logic, validation and database part, it manipulates it and saved back to database

11. Can i use ASP.NET MVC in Windows application
No. Model, View, controller framework is used to create web applications only, in windows you can Model, View, Presenter model

12. What is Razor in ASP.NET MVC ?
As word suggest Razor is acts like cleaner, it just trim the coding brackets and allow new style of coding
see below snippet

//in Classic ASP.NET we uses brackets to render variable
<ol>
<% foreach (var empname in Model)
{ %>
 <li> <% empname.name %> </li>
<% }%>
</ol>

//in ASP.MVC, Razor cleans unused tags and make it faster
<ol>
@foreach (var empname in Model)
{ 
 <li> @empname.name </li>
}
</ol>
13. What is partial view
It is like a user control in asp.net we can use them multiple time, its a reusable view.Partial and RenderPartial methods are used to show partial view
see below snippet
<div>@Html.Partial("_Test")</div>
<div>@{Html.RenderPartial("_Test")}</div>
14. What are the different result ASP.NET MVC can produce
Basically ASP.NET MVC produce only one result, that is 'ActionResult' but it has again different sub class like,
1. ViewResult - Get the response and render specific view.
2. PartialViewResult - Renders a specific but partial view to the response
3. EmptyResult - Return an empty result
4. RedirectResult - Returns an HTTP redirection to a given URL
5. RedirectToRouteResult - Depending on the routing engine get the URL and redirect the result
6. JsonResult - Return given ViewData object to JSON format
7. JavaScriptResult - Return code piece of Javascript that can later execute on client machine
8. ContentResult - Return content to the response
9. FileContentResult - Returns a file with content to the client
10.FileStreamResult - Returns a file to the client but in the form of a Stream
11.FilePathResult - Returns a file with path to the client

15. How to add style sheet in ASP.NET MVC
it is same like your classic ASP.NET
<link rel="StyleSheet" href="@Href(test.css)" type="text/css" />
16.What is the HTML Helper in ASP.NET MVC ?
HTML Helper is like a Classic ASP.NET controls but they are very light weight in comparison with traditional controls, an HTML helper does not have an event model and a view state.
all HTML links and HTML form elements are the part of HTML helper class
e.g. see below HTML link control in HTML Helper

@Html.ActionLink("Check this Website", "Newwebsite")
//when we run this code on Browser we get following output in HTML
<a href="Newwebsite">Check this Website</a>
17. What is minification, and why it is necessary ?
Minification is the process of reducing the size of script and CSS files by removing blank spaces, comments. This process removes whitespaces and comments, it will leads to minimize in file size, and thus increasing performance.
see below snippet
//simple javascript code is below
var a = 10;
a = a + 1;
a = a * 2;

//after minification we will get
var a=10;a=a+1;a=a*2;
Now with above code you can see your .js file size get reduced

18.What is Web API 's in ASP.NET MVC ?
- Web API is a new framework for building on HTTP to consuming Services over REST, it support wide range of Web browsers,desktop,mobile, smart phones

19. What is display Modes ?
with the help of Display Modes, Views selected automatically by application depending on the browser. e.g. for desktop browser application return URL as 'Views\test\Login.cshtml' and for same application mobile browsers will redirect to 'Views\test\Login.mobile.cshtml'

Summing up
We have seen very basic and frequently asked Q&A series, In next part of this Article I will cover more complex scenario's about ASP.NET MVC, till then enjoy this stuff.

Comments/Suggestions/Doubts are always welcome

Thanks
koolprasad2003

27 comments:

  1. Replies
    1. Prasad Daily Dotnet Tricks: Asp.Net Mvc Interview Questions And Answers >>>>> Download Now

      >>>>> Download Full

      Prasad Daily Dotnet Tricks: Asp.Net Mvc Interview Questions And Answers >>>>> Download LINK

      >>>>> Download Now

      Prasad Daily Dotnet Tricks: Asp.Net Mvc Interview Questions And Answers >>>>> Download Full

      >>>>> Download LINK 7O

      Delete
  2. This website have good collection of Asp.net MVC interview questions and i got some additional questions and its answers from https://windowserrors.org/asp-net-mvc-interview-questions/ and i fully hope it will helpful.

    ReplyDelete
  3. It is very good blog and useful for students and developer , Thanks for sharing
    .Net Online CourseHyderabad

    ReplyDelete
  4. If I've told you once, I've told you a hundred times. If you think networking is about meeting as many people as you can, telling them about yourself and handing out hundreds of business cards, you are wrong! So what is Quavo Net Worth Forget the traditional definition so I'm not even going to mention it.

    ReplyDelete
  5. Best Seo company in Bangalore : Best SEO Companies in Bangalore: Hire Digimark Agency, best SEO Agency in Bangalore who Can Boost Your SEO Ranking, guaranteed SEO Services; Free SEO Analysis.

    Seo agencies in Bangalore : Digital Marketing Company In Bangalore: DigiMark Agency is one of the Best Digital Marketing companies in Bangalore. Ranked among the Top digital marketing agencies in Bangalore. SEO Company.

    Seo companies in Bangalore : Social Media Marketing company in Bangalore: DigiMark Agency is one of the Best Social Media Marketing agency in Bangalore which provides you the right services.

    ReplyDelete
  6. top nursing colleges in bangalore : Aihs is one of the top nursing colleges in bangalore . Affiliated to Rajiv Gandhi University of Health Sciences. Apply for bsc nursing admission

    Visit: Nursing colleges in bangalore

    ReplyDelete
  7. Personality development training in bangalore , the best personality development training to develop your body language, personal ability. and also we provides health management and sales training

    ReplyDelete
  8. bridal makeup course in bangalore: GlossNGlass is a Top Makeup Studio & Academy in bangalore. We have best bridal makeup in bangalore with price ✓Professional Makeup artists in Bangalore ✓ Bridal makeup in Bangalore ✓Makeup Courses in Bangalore Best Prices

    Visit:makeup artist in bangalore


    bridal makeup courses in bangalore
    : Makeup Courses. Intensive Pro Makeup & Basic Hair Course. Advanced Pro Makeup, Hairstyling & Saree Course. Bridal Makeup Course in Bangalore. Professional Makeup Classes in Bangalore. Basic Hairstyling Courses in Bangalore. Advanced Hairstyling & Design. Advanced Saree Draping. Makeup Courses in Bangalore.

    Visit:makeup artist bangalore

    ReplyDelete
  9. MAAC provides best hair fall treatment in Bangalore one-stop solution to all hair related worries with a team of highly skilled and trained experts. MAAC ensures all the precautions of safety and service are looked into. Maac provides the best hair transplantation facility that is both effective and does not burn a hole in your pockets. MAAC is one of the best hair transplant clinic in bangalore undertaking various types of hair transplantations like the FUE (Follicular unit extraction) and FUT (follicular unit strip surgery) as well as the Direct Hair Transplantation and the Synthetic Hair Transplantation.
    VISIT:
    best hair transplantation clinic in bangalore

    ReplyDelete
  10. Prp Treatment in Bangalore: MAAC has an expertise in Hair fall treatment, with years of experience in PRP for hair loss, our experts provide the best hair loss treatment in bangalore.
    prp treatment cost in bangalore

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

    ReplyDelete

  12. ABBS School of Law is one of the top law colleges in bangalore ,Affiliated to Karnataka State Law University and Approved by Bar Council of India, New Delhi
    top law colleges in bangalore

    ReplyDelete
  13. See Daily Satta Number online and win. Online Satta Number Chart.

    Satta King, Sattaking

    ReplyDelete

  14. Thanks, this is generally helpful.
    Still, I followed step-by-step your method in this
    dot net online training
    Dot net online training hyderabad

    ReplyDelete
  15. Most of the time I don’t make comments on websites, but I'd like to say that this article really forced me to do so. Really nice post! digital marketing questions

    ReplyDelete
  16. Superb post, we enjoyed each and everything as written in your post. Thank you for this informative article because it’s really helpful, We are the Best Digital marketing company who will help you with your plan’s to execute & optimize your marketing challenges. We will work & collaborate with senior members to track and measure performance, and provide results for all your Digital Marketing challenges

    ReplyDelete
  17. Prasad Daily Dotnet Tricks: Asp.Net Mvc Interview Questions And Answers >>>>> Download Now

    >>>>> Download Full

    Prasad Daily Dotnet Tricks: Asp.Net Mvc Interview Questions And Answers >>>>> Download LINK

    >>>>> Download Now

    Prasad Daily Dotnet Tricks: Asp.Net Mvc Interview Questions And Answers >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete
  18. Enjoy your DevOps Career with the best DevOps Training in Chennai from Infycle Technologies, one of the best software training institutes in Chennai. Infycle also provides the major courses of the software world like AWS training, Azure training, Big Data, and Hadoop Training, Data Science training, with 100% placement opportunities. To have the best job with a high salary package, reach us at 7504633633.

    ReplyDelete