MVC 3
MVC 3
1. M - Model
2. V - View
3. C - Controller
Is it possible to combine ASP.NET webforms and ASP.MVC and develop a single web
application?
Yes, it is possible to combine ASP.NET webforms and ASP.MVC and develop a single web application.
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 asp.net mvc over asp.net 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 - ASP.NET MVC or
ASP.NET Webforms?
ASP.NET MVC
Is it possible to unit test an MVC application without running the controllers in an ASP.NET
process?
Yes, all the features in an asp.net MVC application are interface based and hence mocking is much
easier. So, we don't have to run the controllers in an ASP.NET process for unit testing.
What are the 3 segments of the default route, that is present in an ASP.NET MVC application?
1st Segment - Controller Name
2nd Segment - Action Method Name
3rd Segment - Parameter that is passed to the action method
Example: http://pragimtech.com/Customer/Details/5
Controller Name = Customer
Action Method Name = Details
Parameter Id = 5
ASP.NET MVC application, makes use of settings at 2 places for routing to work correctly. What
are these 2 places?
1. Web.Config File : ASP.NET routing has to be enabled here.
2. Global.asax File : The Route table is created in the application Start event handler, of the Global.asax
file.
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.
What are the levels at which filters can be applied in an asp.net mvc application?
1. Action Method
2. Controller
3. Application
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?
<%= %>
When using razor views, do you have to take any special steps to protect your asp.net 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 asp.net master pages. What is asp.net 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 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 ASP.NET and this is one of those ASP.NET
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 ASP.Net 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.
System.Web.Mvc namespace
Contains classes and interfaces that support the MVC pattern for ASP.NET Web applications. This
namespace includes classes that represent controllers, controller factories, action results, views,
partial views, and model binders.
System.Web.Mvc.Ajax namespace
Contains classes that support Ajax scripts in an ASP.NET MVC application. The namespace includes
support for Ajax scripts and Ajax option settings.
System.Web.Mvc.Async namespace
Contains classes and interfaces that support asynchronous actions in an ASP.NET MVC application
System.Web.Mvc.Html 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 MVC.NET?
The solution is in depended from MVC.NET 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
MVC.NET provides helper function to check for ajax requests which internally inspects X-Requested-
With request header to set IsAjax flag.
HelperPage.IsAjax Property
Gets a value that indicates whether Ajax is being used during the request of the Web page.
Namespace: System.Web.WebPages
Assembly: System.Web.WebPages.dll
However, same can be achieved by checking requests header directly:
Request["X-Requested-With"] == “XmlHttpRequest”
“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.”
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 Asp.Net Webform. The
Url routing system in Asp.Net 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 Global.asax 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 ASP.NET MVC?
Create a java-script function:
<script type="text/javascript">
function selectedIndexChanged() {
}
</script>
Call the function:
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.
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 ASP.NET
System.Web.UI.Page 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 ASP.NET? 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
ASP.NET 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 ASP.NET? Where is ASP.NET 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
Assembly.Load().
<a href="Can-you-create-an-MVC-Unit-
Test-Project-in-Visual-Studio-
Standard.aspx">Can you create an MVC
Unit Test Case in VS Standard?</a><br />
<a href="How-are-CSRF-attacks-avoided-in-ASPNET-MVC-
Framework.aspx">How are CRSF attacks avoided in
ASP.NET MVC Framework?</a><br />
<a href="How-does-a-thread-pool-process-requests-
What-is-thread-starvation.aspx">What is thread
starvation? What are thread pools and how are they
processed?</a><br />
<a href="How-to-create-a-view-for-multiple-
models.aspx">How to create a View for multiple models in
MVC?</a><br />
<a href="How-to-create-an-MVC-project-in-ASPNET-
MVC.aspx">How are MVC projects created?</a><br />
<a href="How-to-implement-a-Gridview-in-ASPNET-
MVC.aspx">What is the best way to implement a Gridview
control in the ASP.NET MVC Framework?</a><br />
<a href="How-to-use-validation-helpers-in-ASPNET-
MVC.aspx">How do we use Validation Helpers in ASP.NET
MVC?</a><br />
<a href="Is-MVC-a-framework-or-a-design-pattern-What-
is-MVC.aspx">Is MVC a Framework or a Design Pattern?
</a><br />
<a href="Point-out-some-advantages-of-the-MVC-
Framework.aspx">Point out some of the key advantages
of the MVC Framework</a><br />
<a href="What-are-the-other-popular-MVC-Frameworks-
besides-the-ASPNET-MVC-Framework.aspx">Besides
ASP.NET MVC, which ones are the other popular MVC
Frameworks around?</a><br />
<a href="What-is-an-asynchronous-controller-in-ASPNET-
MVC.aspx">Explain the use of an Asynchronous Controller
in ASP.NET</a><br />
<a href="Which-are-the-Validation-Helpers-available-in-
ASPNET-MVC.aspx">Name the validation helpers available
in ASP.NET MVC Framework</a><br />
<a href="Why-is-it-suggested-not-to-use-controls-such-as-
GridView-Repeater-DataList-with-the-ASPNET-MVC-
Framework.aspx">Should we use Gridview, Repeater,
Datalist in ASP.NET MVC Framework? Explain.</a>
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.
ASP.NET MVC - Explaining MVC
ASP.NET MVC procedure to handle the process request using MHPM events
Function of Razor
Program to call the js function - change in dropdown list made in ASP.NET MVC
http://www.globalguideline.com/interview_questions/Questions.php?
sc=ASP_Dot_Net_MVC&page=1
http://mr-ponna.com/Questions-by-Technology/1/1/ASP-NET-Interview-Questions-and-Answers/