Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Asp.net mvc interview questions and answers for freshers and experienced


What is MVC ?
MVC stands for Model, View , Control. Its a lightweight, highly testable framework that is integrated with existing ASP.NET features
Model is basically a business entity which is used to represent the application data.
View is the presentation layer of ASP.Net MVC and  represents the UI components like CSS, jQuery, html etc. It is only responsible for displaying the
data that is received from the controller as the result.
Controller is responsible to process incoming requests. It receives input from users via the View,
then process the user's data with the help of Model and passing the results back to the View.

What are advantages of ASP.Net MVC over ASP.NET?
MVC Provides a clean separation of concerns among UI Presentationlayer, model Entities and Business Logic Controller.
Easy to UNIT Test.
URL routing - MVC framework supports URL routing that helps to build
a more comprehensible and searchable URLs in your application

What is difference between ASP.NET and MVC? 
The main differences between ASP.NET and MVC are given below:
ASP.NET Web Form follows a traditional event driven development model.
ASP.NET MVC is a lightweight and follow MVC (Model,View, and Controller) pattern based development model.
ASP.NET Web Form has server controls. ASP.NET MVC has html helpers.
ASP.NET Web Form has state management (like as
view state, session) techniques.
ASP.NET Web Form has file-based URLs means filename exist in the URLs must have its physically
existence.
ASP.NET MVC has no automatic state management techniques.
ASP.NET MVC has route-based URLs means URLs are divided into controllers and actions and moreover it is based on controller not on physical file.
ASP.NET Web Form follows WebForm Syntax ASP.NET MVC follow customizable syntax (Razor as default)
In ASP.NET Web Form, Web Forms (ASPX) i.e. views are tightly coupled to Code behind (ASPX.CS) i.e. logic.
ASP.NET Web Form has Master Pages for consistent look and feels.
ASP.NET Web Form has User Controls for code reusability.

ASP.NET Web Form has built-in data controls and
best for rapid development with powerful data
access.
In ASP.NET MVC, Views and logic are kept separately.
ASP.NET MVC has Layouts for consistent look and feels.
ASP.NET MVC has Partial Views for code re-usability.
ASP.NET MVC is lightweight, provide full control over
mark-up and support many features that allow fast & agile
development. Hence it is best for developing interactive
web application with latest web standards.
ASP.NET Web Form is not Open Source. ASP.NET Web MVC is an Open Source.

Explain Bundle.Config ?
"BundleConfig.cs" is used to register the bundles by the bundling and minification system.

What are the possible Razor view extensions?
Below are the two types of extensions razor view can have –
.cshtml – In C# programming language this extension will be used.
.vbhtml - In VB programming language this extension will be used.

What is PartialView in MVC?
PartialView is similar to UserControls in traditional web forms. For re-usability purpose partial views are used. Since it’s been shared with multiple views these are kept in shared folder. Partial Views can be rendered in following ways –
Html.Partial()
Html.RenderPartial()

Which are the important namespaces used in ASP.Net MVC?
Below are the important namespaces used in ASP.Net MVC -
System.Web.ASP.Net MVC
System.Web.ASP.Net MVC.Ajax
System.Web.ASP.Net MVC.Html
System.Web.ASP.Net MVC.Async

What is Layout in ASP.Net MVC?
Layout pages are similar to master pages in traditional web forms. This is used to set the common
look across multiple pages. In each child page we can find :
@ {
Layout = "~/Views/Shared/SampleLayout.cshtml";
}
This indicates child page uses TestLayout page as it's master page.

Can you explain RenderBody and RenderPage in ASP.Net MVC?
RenderBody is like ContentPlaceHolder in web forms. This will exist in layout page and it will
render the child pages/views.
Layout page will have only one RenderBody method. RenderPage
also exists in Layout page and multiple RenderPage can be there in Layout page.

What is ViewStart Page in ASP.Net MVC?
This page is used to make sure common layout page will be used for multiple views. Code written
in this file will be executed first when application is being loaded.

Explain the methods used to render the views in ASP.Net MVC?
Below are the methods used to render the views from action -
View : To return the view from action.
PartialView : To return the partial view from action.
RedirectToAction : To Redirect to different action which can be in same controller or in
different controller.
Redirect : Similar to "Response.Redirect" in webforms, used to redirect to specified URL.
RedirectToRoute : Redirect to action from the specified URL but URL in the route table has
been matched.

What are the sub types of ActionResult?
ActionResult is used to represent the action method result.
Below are the subtypes of ActionResult:
ViewResult
PartialViewResult
RedirectToRouteResult
RedirectResult
JavascriptResult
JSONResult
FileResult
HTTPStatusCodeResult

Explain URL Routing
It is a pattern matching system that
matches the incoming request to the registered URL patterns in the Route Table

How to define a route in ASP.NET MVC?
Ans. You can define a route in ASP.NET MVC as given below:
public static void RegisterRoutes(RouteCollection routes)
{
     routes.MapRoute(
     "Default", // Route name
     "{controller}/{action}/{id}", // Route Pattern
     new
        {
                controller = "Home",
                action = "Index",
                id = UrlParameter.Optional
        }// Default values for above defined parameters
      );
 }
 protected void Application_Start()
 {
     RegisterRoutes(RouteTable.Routes);
     //TODO:
 }

Always remember route name should be unique across the entire application. Route name can’t be duplicate.
In above example we have defined the Route Pattern {controller}/{action}/{id} and also provide the default values
for controller, action and id parameters.



This post first appeared on Asp.netSourceCodes, please read the originial post: here

Share the post

Asp.net mvc interview questions and answers for freshers and experienced

×

Subscribe to Asp.netsourcecodes

Get updates delivered right to your inbox!

Thank you for your subscription

×