MVC (full form Model View Controller)is a software architecture or
application design model containing 3 interconnected verticals or portions.
These 3 portions are the model (data associated with the application),
the view (which is the user interface of an MVC application), and
the controller (the processes that are responsible for handling the input).
What are the different return types used by the controller
action method in MVC?
The various return types of controller action methods in MVC are:
View Result
JSON Result
Content Result
Redirect Result
JavaScript Result
Explain the MVC Application life cycle.
Web applications usually have 2 primary execution steps. These are:
Understanding the request.
Sending an appropriate response based on the type of request.
The same thing can be related to MVC applications also whose life cycle
has 2 foremost phases:
For creating a request object.
For sending the response to any browser.
How will you maintain the sessions in MVC?
The sessions of an MVC can be maintained in 3 possible ways:
viewdata
temp data and
view bag
What are the Filters in MVC?
In MVC, controllers define action methods and these action methods
generally have a one-to-one relationship with UI controls such as clicking a
button or a link, etc. For example, in one of our previous examples, the
UserController class contained methods UserAdd, UserDelete, etc.
But many times we would like to perform some action before or after a
particular operation. For achieving this functionality, ASP.NET MVC
provides a feature to add pre and post-action behaviors on the controller's
action methods.
Types of Filters
ASP.NET MVC framework supports the following action filters,
Action Filters
Action filters are used to implement logic that gets executed before
and after a controller action executes. We will look at Action Filters in
detail in this chapter.
Authorization Filters
Authorization filters are used to implement authentication and
authorization for controller actions.
Result Filters
Result filters contain logic that is executed before and after a view
result is executed. For example, you might want to modify a view
result right before the view is rendered to the browser.
Exception Filters
Exception filters are the last type of filter to run. You can use an
exception filter to handle errors raised by either your controller
actions or controller action results. You can also use exception filters
to log errors.
Action filters are one of the most commonly used filters to perform
additional data processing, or manipulating the return values or canceling
the execution of an action or modifying the view structure at run time.
What is the use of ActionFilters in MVC?
ActionFilters are used for executing the logic while MVC action is
executed. Furthermore, action filters permit the implementation of pre
and post-processing logic and action methods
What is TempData in MVC?
TempData can be defined as a dictionary object used for storing data for
a short period of time. This is the MVC’s TempDataDictionary class which
acts as a Controller base-class’s instance property. TempData has the
ability to preserve data for an HTTP request.
What is ViewStart?
A new layout called _ViewStart is introduced by the Razor View Engine
that is applied to all views automatically. ViewStart is executed at the
very beginning followed by the start rendering as well as other views.
Define Default Route in MVC?
The default Route of project templates in MVC includes a generic route
that makes use of the given URL resolution for breaking the URL based
on the request into 3 tagged segments. URL: “{controller} / {action} /
{id}”
42. Explain briefly the GET and POST Action types?
The GET Action Type is implemented for requesting the data from
a particular resource. Using these GET requests, a developer can
pass the URL (that is compulsory).
The POST Action Type is implemented for submitting the data that
needs to be handled to a certain resource. Using these POST
requests, a developer can move with the URL, which is essential
along with the data.
What is Razor in MVC?
ASP.NET MVC has always supported the concept of "view engines" - which
are the pluggable modules that implement different template syntax
options. The "default" view engine for ASP.NET MVC uses the
same .aspx/.ascx/. master file templates as ASP.NET Web Forms. Other
popular ASP.NET MVC view engines are Spart&Nhaml.
What is difference between MVC and Web Forms?
Answer - ASP.Net MVC / Web Forms difference
The following are some difference.
ASP.Net MVC ASP.Net Web Forms
View and logic are separate, it has
No separation of concerns; Views are tightly coupled with
separation of concerns theory. MVC 3
logic (.aspx.cs /.vb file).
onwards has .aspx page as .cshtml.
Introduced concept of routing for route
based URL. Routing is declared in File-based routing .Redirection is based on pages.
Global.asax for example.
Support Razor syntax as well as .aspx Support web forms syntax only.
State management handled via
Tempdata, ViewBag, and View Data.
Since the controller and view are not State management handled via View State. Large
dependent and also since there is no viewstate, in other words increase in page size.
view state concept in ASP.NET, MVC
keeps the pages lightweight.
Partial Views User Controls
HTML Helpers Server Controls
Multiple pages can have the same
controller to satisfy their requirements. A Each page has its own code, in other words direct
controller may have multiple Actions dependency on code. For example Sachin.aspx is
(method name inside the controller dependent on Sachin.aspx.cs (code behind) file.
class).
Unit Testing is quite easier than ASP.Net
Web forms Since a web form and code Direct dependency, tight coupling raises issues in testing.
are separate files.
layouts Master pages