What are the 3 main components of an [Link] MVC application?
1. M - Model
2. V - View
3. C - Controller
In which assembly is the MVC framework defined?
[Link]
Is it possible to combine [Link] webforms and [Link] and develop a single web
application?
Yes, it is possible to combine [Link] webforms and [Link] and develop a single web application.
What does Model, View and Controller represent in an MVC application?
Model: Model represents the application data domain. In short the applications business logic is
contained in the model.
View: Views represent the user interface, with which the end users interact. In short the all the user
interface logic is contained in the view.
Controller: Controller is the component that responds to user actions. Based on the user actions, the
respective controller, work with the model, and selects a view to render that displays the user
interface. The user input logic is contained in the controller.
What is the greatest advantage of using [Link] mvc over [Link] webforms?
It is difficult to unit test UI with webforms, where views in mvc can be very easily unit tested.
Which approach provides better support for test driven development - [Link] MVC or
[Link] Webforms?
[Link] MVC
What are the advantages of [Link] MVC?
1. Extensive support for TDD. With [Link] MVC, views can also be very easily unit tested.
2. Complex applications can be easily managed
3. Seperation of concerns. Different aspects of the application can be divided into Model, View and
Controller.
4. [Link] MVC views are light weight, as they do not use viewstate.
Is it possible to unit test an MVC application without running the controllers in an [Link]
process?
Yes, all the features in an [Link] MVC application are interface based and hence mocking is much
easier. So, we don't have to run the controllers in an [Link] process for unit testing.
Is it possible to share a view across multiple controllers?
Yes, put the view into the shared folder. This will automatically make the view available across multiple
controllers.
What is the role of a controller in an MVC application?
The controller responds to user interactions, with the application, by selecting the action method to
execute and also selecting the view to render.
Where are the routing rules defined in an [Link] MVC application?
In Application_Start event in [Link]. Using RouteMap method of RouteCollection.
Name a few different return types of a controller action result method?
The following are just a few return types of a controller action method. In general an action method
can return an instance of any class that derives from ActionResult class.
1. ViewResult
2. JavaScriptResult
3. RedirectResult
4. ContentResult
5. JsonResult
What is the significance of NonActionAttribute?
In general, all public methods of a controller class are treated as action methods. If you want prevent
this default behaviour, just decorate the public method with NonActionAttribute.
What is the significance of [Link] routing?
[Link] MVC uses [Link] routing, to map incoming browser requests to controller action methods.
[Link] Routing makes use of route table. Route table is created when your web application first
starts. The route table is present in the [Link] file.
What are the 3 segments of the default route, that is present in an [Link] MVC application?
1st Segment - Controller Name
2nd Segment - Action Method Name
3rd Segment - Parameter that is passed to the action method
Example: [Link]
Controller Name = Customer
Action Method Name = Details
Parameter Id = 5
[Link] MVC application, makes use of settings at 2 places for routing to work correctly. What
are these 2 places?
1. [Link] File : [Link] routing has to be enabled here.
2. [Link] File : The Route table is created in the application Start event handler, of the [Link]
file.
What is the advantage of using [Link] routing?
In an [Link] web application that does not make use of routing, an incoming browser request
should map to a physical file. If the file does not exist, we get page not found error.
An [Link] web application that does make use of routing, makes use of URLs that do not have to
map to specific files in a Web site. Because the URL does not have to map to a file, you can use URLs
that are descriptive of the user's action and therefore are more easily understood by users.
What are the 3 things that are needed to specify a route?
1. URL Pattern - You can include placeholders in a URL pattern so that variable data can be passed to
the request handler without requiring a query string.
2. Handler - The handler can be a physical file such as an .aspx file or a controller class.
3. Name for the Route - Name is optional.
Is the following route definition a valid route definition?
{controller}{action}/{id}
No, the above definition is not a valid route definition, because there is no literal value or delimiter
between the placeholders. Therefore, routing cannot determine where to separate the value for the
controller placeholder from the value for the action placeholder.
What is the use of the following default route?
{resource}.axd/{*pathInfo}
This route definition, prevent requests for the Web resource files such as [Link] or
[Link] from being passed to a controller.
What is the difference between adding routes, to a webforms application and to an mvc
application?
To add routes to a webforms application, we use MapPageRoute() method of the RouteCollection
class, where as to add routes to an MVC application we use MapRoute() method.
How do you handle variable number of segments in a route definition?
Use a route with a catch-all parameter. An example is shown below. * is referred to as catch-
all parameter.
controller/{action}/{*parametervalues}
What are the 2 ways of adding constraints to a route?
1. Use regular expressions
2. Use an object that implements IRouteConstraint interface
Give 2 examples for scenarios when routing is not applied?
1. A Physical File is found that Matches the URL Pattern - This default behaviour can be overridden
by setting the RouteExistingFiles property of the RouteCollection object to true.
2. Routing Is Explicitly Disabled for a URL Pattern - Use the [Link]() method to
prevent routing from handling certain requests.
What is the use of action filters in an MVC application?
Action Filters allow us to add pre-action and post-action behaviour to controller action methods.
If I have multiple filters implemented, what is the order in which these filters get executed?
1. Authorization filters
2. Action filters
3. Response filters
4. Exception filters
What are the different types of filters, in an [Link] MVC application?
1. Authorization filters
2. Action filters
3. Result filters
4. Exception filters
Give an example for Authorization filters in an [Link] mvc application?
1. RequireHttpsAttribute
2. AuthorizeAttribute
Which filter executes first in an [Link] mvc application?
Authorization filter
What are the levels at which filters can be applied in an [Link] mvc application?
1. Action Method
2. Controller
3. Application
[b]Is it possible to create a custom filter?
Yes
What filters are executed in the end?
Exception Filters
Is it possible to cancel filter execution?
Yes
What type of filter does OutputCacheAttribute class represents?
Result Filter
What are the 2 popular [Link] mvc view engines?
1. Razor
2. .aspx
What symbol would you use to denote, the start of a code block in razor views?
@
What symbol would you use to denote, the start of a code block in aspx views?
<%= %>
In razor syntax, what is the escape sequence character for @ symbol?
The escape sequence character for @ symbol, is another @ symbol
When using razor views, do you have to take any special steps to protect your [Link] mvc
application from cross site scripting (XSS) attacks?
No, by default content emitted using a @ block is automatically HTML encoded to protect from cross
site scripting (XSS) attacks.
When using aspx view engine, to have a consistent look and feel, across all pages of the
application, we can make use of [Link] master pages. What is [Link] master pages equivalent,
when using razor views?
To have a consistent look and feel when using razor views, we can make use of layout pages. Layout
pages, reside in the shared folder, and are named as _Layout.cshtml
What are sections?
Layout pages, can define sections, which can then be overriden by specific views making use of the
layout. Defining and overriding sections is optional.
What are the file extensions for razor views?
1. .cshtml - If the programming lanugaue is C#
2. .vbhtml - If the programming lanugaue is VB
How do you specify comments using razor syntax?
Razor syntax makes use of @* to indicate the begining of a comment and *@ to indicate the end. An
example is shown below.
@* This is a Comment *@
What is MVC?
MVC is a framework methodology that divides an application’s implementation into three component
roles: models, views, and controllers.
“Models” in a MVC based application are the components of the application that are responsible for
maintaining state. Often this state is persisted inside a database (for example: we might have a
Product class that is used to represent order data from the Products table inside SQL).
“Views” in a MVC based application are the components responsible for displaying the application’s
user interface. Typically this UI is created off of the model data (for example: we might create an
Product “Edit” view that surfaces textboxes, dropdowns and checkboxes based on the current state of
a Product object).
“Controllers” in a MVC based application are the components responsible for handling end user
interaction, manipulating the model, and ultimately choosing a view to render to display UI. In a MVC
application the view is only about displaying information – it is the controller that handles and
responds to user input and interaction.
Which are the advantages of using MVC Framework?
MVC is one of the most used architecture pattern in [Link] and this is one of those [Link]
interview question to test that do you really understand the importance of model view controller.
1. It provides a clean separation of concerns between UI and model.
2. UI can be unit test thus automating UI testing.
3. Better reuse of views and model. You can have multiple views which can point to the same model
and also vice versa.
4. Code is better organized.
What is Razor View Engine?
Razor view engine is a new view engine created with [Link] MVC model using specially designed
Razor parser to render the HTML out of dynamic server side code. It allows us to write Compact,
Expressive, Clean and Fluid code with new syntaxes to include server side code in to HTML.
What is namespace of [Link] mvc?
[Link] MVC namespaces and classes are located in the [Link] assembly.
[Link] namespace
Contains classes and interfaces that support the MVC pattern for [Link] Web applications. This
namespace includes classes that represent controllers, controller factories, action results, views,
partial views, and model binders.
[Link] namespace
Contains classes that support Ajax scripts in an [Link] MVC application. The namespace includes
support for Ajax scripts and Ajax option settings.
[Link] namespace
Contains classes and interfaces that support asynchronous actions in an [Link] MVC application
[Link] namespace
Contains classes that help render HTML controls in an MVC application. The namespace includes
classes that support forms, input controls, links, partial views, and validation.
How to identify AJAX request with C# in [Link]?
The solution is in depended from [Link] framework and universal across server-side technologies.
Most modern AJAX applications utilize XmlHTTPRequest to send async request to the server. Such
requests will have distinct request header:
X-Requested-With = XMLHTTPREQUEST
[Link] provides helper function to check for ajax requests which internally inspects X-Requested-
With request header to set IsAjax flag.
[Link] Property
Gets a value that indicates whether Ajax is being used during the request of the Web page.
Namespace: [Link]
Assembly: [Link]
However, same can be achieved by checking requests header directly:
Request["X-Requested-With"] == “XmlHttpRequest”
What is Repository Pattern in [Link] MVC?
Repository pattern is usefult for decoupling entity operations form presentation, which allows easy
mocking and unit testing.
“The Repository will delegate to the appropriate infrastructure services to get the job done.
Encapsulating in the mechanisms of storage, retrieval and query is the most basic feature of a
Repository implementation”
“Most common queries should also be hard coded to the Repositories as methods.”
Which [Link] to implement repository pattern Controller would have 2 constructors on
parameterless for framework to call, and the second one which takes repository as an input:
class myController: Controller
{
private IMyRepository repository;
// overloaded constructor
public myController(IMyRepository repository)
{
[Link] = repository;
}
// default constructor for framework to call
public myController()
{
//concreate implementation
myController(new someRepository());
}
...
public ActionResult Load()
{
// loading data from repository
var myData = [Link]();
}
}
What is difference between MVC(Model-View-Controller) and MVP(Model-View-
Presenter)?
The main difference between the two is how the manager (controller/presenter) sits in the
overall architecture.
All requests goes first to the Controller
MVC pattern puts the controller as the main ‘guy’ in charge for running the show. All application
request comes through straight to the controller, and it will decide what to do with the request.
Giving this level of authority to the controller isn’t an easy task in most cases. Users interaction in an
application happen most of the time on the View.
Thus to adopt MVC pattern in a web application, for example, the url need to become a way of
instantiating a specific controller, rather than ‘simply’ finding the right View (webform/ html page) to
render out. Every requests need to trigger the instantiation of a controller which will eventually
produce a response to the user.
This is the reason why it’s alot more difficult to implement pure MVC using [Link] Webform. The
Url routing system in [Link] webform by default is tied in to the server filesystem or IIS virtual
directory structure. Each of these aspx files are essentially Views which will always get called and
instantiated first before any other classes in the project. (Of course I’m overgeneralizing here. Classes
like IHttpModule, IHttpHandler and [Link] would be instantiated first before the aspx web form
pages).
MVP (Supervising Controller) on the other hand, doesn’t mind for the View to take on a bigger role.
View is the first object instantiated in the execution pipeline, which then responsible for passing any
events that happens on itself to the Presenter.
The presenter then fetch the Models, and pass it back to the view for rendering.
How to call javascript function on the change of Dropdown List in [Link] MVC?
Create a java-script function:
<script type="text/javascript">
function selectedIndexChanged() {
}
</script>
Call the function:
<%:[Link](x => [Link],
new SelectList([Link], "Value", "Text"),
"Please Select a product", new { id = "dropDown1",
onchange="selectedIndexChanged()" })%>
How route table is created in [Link] MVC?
When an MVC application first starts, the Application_Start() method is called. This method, in turn,
calls the RegisterRoutes() method. The RegisterRoutes() method creates the route table.
How do you avoid XSS Vulnerabilities in [Link] MVC?
Use the syntax in [Link] MVC instead of using in .net framework 4.0.
Explain how to access Viewstate values of this page in the next page?
PreviousPage property is set to the page property of the nest page to access the viewstate value of the
page in the next page.
Page poster = [Link];
Once that is done, a control can be found from the previous page and its state can be read.
Label posterLabel = [Link]("myLabel");
string lbl = [Link];
How to create dynamic property with the help of viewbag in [Link] MVC?
or
What is difference between Viewbag and Viewdata in [Link] MVC?
The basic difference between ViewData and ViewBag is that in ViewData instead creating dynamic
properties we use properties of Model to transport the Model data in View and in ViewBag we can
create dynamic properties without using Model data.
What is Routing?
A route is a URL pattern that is mapped to a handler. The handler can be a physical file, such as an
.aspx file in a Web Forms application. Routing module is responsible for mapping incoming browser
requests to particular MVC controller actions.
From constructor to destructor (taking into consideration Dispose() and the concept of non-
deterministic finalization), what the are events fired as part of the [Link]
[Link] lifecycle. Why are they important? What interesting things can you do at
each?
What are ASHX files? What are HttpHandlers? Where can they be configured?
What is needed to configure a new extension for use in [Link]? For example, what if I
wanted my system to serve ASPX files with a *.jsp extension?
What events fire when binding data to a data grid? What are they good for?
Explain how PostBacks work, on both the client-side and server-side. How do I chain my own
JavaScript into the client side without losing PostBack functionality?
How does ViewState work and why is it either useful or evil?
What is the OO relationship between an ASPX page and its CS/VB code behind file in
[Link] 1.1? in 2.0?
What happens from the point an HTTP request is received on a TCP/IP port up until the Page
fires the On_Load event?
How does IIS communicate at runtime with [Link]? Where is [Link] at runtime in IIS5?
IIS6?
What is an assembly binding redirect? Where are the places an administrator or developer
can affect how assembly binding policy is applied?
Compare and contrast LoadLibrary(), CoCreateInstance(), CreateObject() and
[Link]().
How route table is
created in [Link] 1 2012/12/07
MVC4?
What is namespace of [Link] mvc? 1 2012/12/07
Give an example for Authorization filters in an
1 2012/11/01
[Link] mvc application?
What filters are executed in the end? 1 2012/11/01
What type of filter does OutputCacheAttribute 1 2012/11/01
class represents?
What symbol would you use to denote, the start of
1 2012/11/01
a code block in razor views?
In razor syntax, what is the escape sequence
1 2012/11/01
character for @ symbol?
[Link] namespace? 1 2012/09/07
What is Razor View Engine? 1 2012/09/07
What are the 2 popular [Link] mvc view engines? 1 2012/09/07
What are the file extensions for razor views? 1 2012/09/07
How do you specify comments using razor syntax? 1 2012/09/07
What are the [Link] MVC folder conventions? 1 2012/07/16
What is the main function of URL routing system in
1 2012/07/16
[Link] MVC?
What are the namespace classes used in [Link]
1 2012/07/16
MVC?
What is Repository Pattern in [Link] MVC? 1 2012/07/16
What is Repository Pattern in [Link] MVC? 1 2012/07/16
What is the page lifecycle of an [Link] MVC? 1 2012/07/16
What are the different types of filters, in an [Link]
1 2012/05/19
mvc application?
What is the use of action filters in an MVC
1 2012/05/19
application?
What are the 2 ways of adding constraints to a
1 2012/05/19
route?
What are three segments of the default route, that
1 2012/05/19
is present in an [Link] MVC application?
What is the significance of [Link] routing? 1 2012/05/19
What is the significance of NonActionAttribute? 1 2012/05/19
Is it possible to share a view across multiple
1 2012/05/19
controllers?
What is the greatest advantage of using [Link]
1 2012/05/19
mvc over [Link] webforms?
In which assembly is the MVC framework defined? 1 2012/05/19
What are the 3 main components of an [Link]
1 2012/05/19
MVC application?
What is the 'page lifecycle' of an [Link] MVC? 1 2011/10/11
How to call javascript function on the change of
1 2011/10/11
dropdownlist in [Link] MVC?
How route table created in [Link] MVC? 1 2011/10/11
How do you avoid XSS vulnerabilities in [Link]
1 2011/10/11
(MVC)?
Explain how to access ViewState value of this page
1 2011/10/11
in the next page.
How to create dynamic property with the help of
1 2011/09/17
ViewBag in [Link] MVC?
What is difference between ViewBag and
1 2011/09/07
ViewData in [Link] MVC?
What is Routing in [Link] MVC? 1 2011/09/07
Explain MVC pattern? 1 2011/09/07
What are the advantages of [Link] MVC? 1 2011/09/07
What is Controller in [Link] MVC? 1 2011/08/29
What is View in [Link] MVC? 1 2011/08/29
What is model in [Link] MVC? 1 2011/08/29
How to identify AJAX request with C# in [Link]? 1 2011/08/29
What is repository patterm in [Link]? 1 2011/08/29
What is namespace of [Link] mvc? 1 2011/08/29
What is [Link] MVC?
<a href="Can-you-create-an-MVC-Unit-
Test-Project-in-Visual-Studio-
[Link]">Can you create an MVC
Unit Test Case in VS Standard?</a><br />
<a href="How-are-CSRF-attacks-avoided-in-ASPNET-MVC-
[Link]">How are CRSF attacks avoided in
[Link] MVC Framework?</a><br />
<a href="How-does-a-thread-pool-process-requests-
[Link]">What is thread
starvation? What are thread pools and how are they
processed?</a><br />
<a href="How-to-create-a-view-for-multiple-
[Link]">How to create a View for multiple models in
MVC?</a><br />
<a href="How-to-create-an-MVC-project-in-ASPNET-
[Link]">How are MVC projects created?</a><br />
<a href="How-to-implement-a-Gridview-in-ASPNET-
[Link]">What is the best way to implement a Gridview
control in the [Link] MVC Framework?</a><br />
<a href="How-to-use-validation-helpers-in-ASPNET-
[Link]">How do we use Validation Helpers in [Link]
MVC?</a><br />
<a href="Is-MVC-a-framework-or-a-design-pattern-What-
[Link]">Is MVC a Framework or a Design Pattern?
</a><br />
<a href="Point-out-some-advantages-of-the-MVC-
[Link]">Point out some of the key advantages
of the MVC Framework</a><br />
<a href="What-are-the-other-popular-MVC-Frameworks-
[Link]">Besides
[Link] MVC, which ones are the other popular MVC
Frameworks around?</a><br />
<a href="What-is-an-asynchronous-controller-in-ASPNET-
[Link]">Explain the use of an Asynchronous Controller
in [Link]</a><br />
<a href="[Link]">What is NerdDinner?
</a><br />
<a href="[Link]">What is Razor?</a><br />
<a href="Which-are-the-Validation-Helpers-available-in-
[Link]">Name the validation helpers available
in [Link] MVC Framework</a><br />
<a href="Why-is-it-suggested-not-to-use-controls-such-as-
GridView-Repeater-DataList-with-the-ASPNET-MVC-
[Link]">Should we use Gridview, Repeater,
Datalist in [Link] MVC Framework? Explain.</a>
[Link] MVC Interview questions :- What is the difference
between tempdata , viewdata and viewbag?
Posted on September 27, 2012by c# and .NET Interview questions
Temp data: - Helps to maintain data when you move from one controller to other
controller or from one action to other action. In other words when you redirect,
“tempdata” helps to maintain data between those redirects. It internally uses session
variables.
View data: - Helps to maintain data when you move from controller to view.
View Bag: - It’s a dynamic wrapper around view data. When you use “Viewbag” type
casting is not required.
[Link] MVC - Explaining MVC
Difference between [Link] MVC and [Link] WebForms
[Link] MVC architecture - different from others
[Link] MVC - Advantages of MVC over WebForms
[Link] MVC - Request Flow
Procedure to create environment for [Link]
[Link] MVC procedure to handle the process request using MHPM events
[Link] MVC flow to process of the request
Features making [Link] more used framework
[Link] MVC folder conventions
Function of New View Engine in [Link]
Function of Razor
[Link] MVC program - Code nuggets to create a simple application
Program in [Link] MVC- Razor view engine to create a simple application
Namespace classes in [Link] MVC
Repository Pattern in [Link] MVC
Difference between MVC and MVP
Page lifecycle of an [Link] MVC
Program to call the js function - change in dropdown list made in [Link] MVC
Function of URL routing system in [Link] MVC
[Link]
sc=ASP_Dot_Net_MVC&page=1
[Link]