REAL-TIME MVC Interview Questions & Answers For [PRACTICE]
MVC Interview Questions and Answers

REAL-TIME MVC Interview Questions & Answers For [PRACTICE]

Last updated on 04th Jul 2020, Blog, Interview Questions

About author

Ramki (Sr Project Manager )

High level Domain Expert in TOP MNCs with 8+ Years of Experience. Also, Handled Around 20+ Projects and Shared his Knowledge by Writing these Blogs for us.

(5.0) | 15212 Ratings 15158

These MVC Interview Questions have been designed specially to get you acquainted with the nature of questions you may encounter during your interview for the subject of MVC As per my experience good interviewers hardly plan to ask any particular question during your interview, normally questions start with some basic concept of the subject and later they continue based on further discussion and what you answer .we are going to cover top 100 MVC Interview questions along with their detailed answers. We will be covering MVC scenario based interview questions MVC interview questions for fresher’s as well as interview MVC questions and answers for experienced

1)Spring MVC .Explain what is MVC?

Ans:

MVC is an abbreviation for Model, View, and Controller. The MVC architectural pattern separates an application into three components – Model, View, and Controller. In this pattern, the model represents the shape of the data and business logic. It maintains and preserves the data of the application. Model objects retrieve and store model state in a database. The view is basically and technically a user interface. The view segment displays the data-using model to the user and also enables them to modify the data. The controller is the part, which handles the user request.

2)List out a few different return types of a controller action method?

Ans:

  • Javascript Result
  • Redirect Result
  • JSON Result
  • Content Result

3) What are the advantages of MVC?

Ans:

Benefits or the advantages of MVC are as follows:

Multiple view support: Because of the separation of the model from the view, the user interface can display multiple views of the same data and at the same time. Change Accommodation: User interfaces tend to change more frequently than business rules.

4) Explain the role of components Presentation, Abstraction, and Control in MVC?

Ans:

Presentation: It is the visual representation of a specific abstraction within the application. Abstraction: It is the business domain functionality within the application.

Control: It is a component that keeps consistency between the abstraction within the system and their presentation to the user. It is also used to communicate with other controls within the system.

5) How to maintain session in MVC?

Ans:

The session can be maintained in MVC by three ways temp data, viewdata, and view bag.

6) What is MVC Application life cycle?

Ans:

Any web application has two main execution steps, first understanding the request and depending on the type of the request, sending out an appropriate response. MVC application life cycle has two main phases, first creating the request object and second sending the response to the browser.

Creating the request object includes four basic steps:

  • Step 1: Fill route
  • Step 2: Fetch route
  • Step 3: Request context created
  • Step 4: Controller instance created

7) What does the MVC Pattern define with 3 logical layers?

Ans:

The MVC model defines web applications with 3 logic layers:

  • The business layer (Model logic)
  • The display layer (View logic)
  • The input control (Controller logic)

The Model is the part of the application, which only handles the logic for the application data. Regularly, the model objects retrieve data (as well as store data) from a database. The View is the part of the application, which takes care of the display of the data. Most often, the views are created from the model data, although there are other, more complicated methods of creating views. The Controller, as the name implies, is the part of the application that handles user interaction.

8) What is Spring MVC?

Ans:

It is a Java framework which is used to build web applications. It follows the Model-View-Controller design pattern. Not just that, it also implements all the basic features of a core Spring Framework like Inversion of Control, Dependency Injection. Spring MVC provides a dignified solution to use MVC in Spring Framework by the help of DispatcherServlet. In this case, DispatcherServlet is a class that receives the incoming request and maps it to the right resource such as Controllers, Models, and Views.

9) What is ASP.NET MVC?

Ans:

ASP.NET MVC is a web application Framework. It is lightweight and highly testable Framework. MVC separates an application into three components — Model, View, and Controller.

10) What is MVC Routing?

Ans:

The URLs in ASP.NET MVC are mapped to action methods and controller instead of physical files of the system. To accurately map action methods and controller to URLs, the routing engine forms appropriate routes. Using this, the controllers can handle specific requests.

11)What are the Filters?

Ans:

Sometimes we want to execute some logic either before the execution of the action method or after the execution. We can use Action Filter for such kind of scenario. Filters define the logic which is executed before or after the execution of the action method. Action Filters are attributes which we can apply to the action methods. Following are the MVC action filter types:

12) What is Partial View in MVC?

Ans:

A partial view is a chunk of HTML that can be safely inserted into an existing DOM. Most commonly, partial views are used to componentize Razor views and make them easier to build and update. It can also be returned directly from controller methods. In this case, the browser still receives text/HTML content but not necessarily HTML content that makes up an entire page. As a result, if a URL that returns a partial view is directly invoked from the address bar of a browser, an incomplete page may be displayed. This may be something like a page that misses title, script and style sheets.

13)Can you explain the page life cycle of MVC?

Ans:

Below mentioned steps define the page life cycle.

  • App initialization
  • Routing
  • Instantiate and execute controller
  • Locate and invoke controller action
  • Instantiate and render view.

14) What is the use of ViewModel in MVC?

Ans:

ViewModel is a plain class with properties, which is used to bind it to a strongly-typed view. ViewModel can have the validation rules defined for its properties using data annotation.

15) What is Database first approach in MVC using Entity Framework?

Ans:

Database First Approach is an alternative or substitutes to the Code First and Model First approaches to the Entity Data Model. The Entity Data Model creates model codes (classes, properties, DbContext, etc.) from the database in the project and that class behaves as the link between database and controller.

There are the following approaches, which are used to connect the database with the application.

  • Database First
  • Model First
  • Code First

16) What do you mean by MVC Scaffolding?

Ans:

  • Scaffolding is a code generation framework for ASP.NET Web applications. Visual Studio includes pre-installed code generators for MVC and Web API projects. You add scaffolding to your project when you want to quickly add the code that interacts with data models. Using scaffolding can reduce the amount of time to develop standard data operations in your project.
  • It consists of page templates, entity page templates, field page templates, and filter templates. These templates are called Scaffold templates and they allow you to quickly build a functional data-driven Website.

17)  Explain the concept of Razor in ASP.NET MVC?

Ans:

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 WebForms. Other popular ASP.NET MVC view engines are Spart & Nhaml. Razor is the new view-engine introduced by MVC 3.

18) Explain the concept of  Default Route in MVC

Ans:

Default Route: The default ASP.NET MVC project templates add a generic route that uses the following URL convention to break the URL for a given request into three named segments.

URL: “{controller}/{action}/{id}”

This route pattern is registered via a call to the MapRoute() extension method of RouteCollection.

19) What is GET and POST Action types?

Ans:

GET Action Type: GET is used to request data from a specified resource. With all the GET requests, we pass the URL, which is compulsory; however, it can take up the following overloads. POST Action Type: Tthe POST is used to submit data to be processed to a specified resource. With all the POST requests, we pass the URL, which is essential and the data. However, it can take up the following overloads.

20) How does View Data differ from View Bag in MVC?

Ans:

  • View Data
  • View Bag
  • ViewData is used to pass data from a controller to view
  • ViewBag is also used to pass data from the controller to the respective view.
  • It is available for the current request only.
  • It is also available for the current request only.
  • Requires typecasting for complex data type and checks for null values to avoid error
  • Doesn’t require typecasting for the complex data type.
  • If redirection occurs, then its value becomes null.
  • If redirection occurs, then its value becomes null.

21) Mention the Benefits of Area in MVC

Ans:

Benefits of Area in MVC are as follows: It allows us to organize models, views, and controllers into separate functional sections of the application, such as administration, billing, customer support and much more. It is easy to integrate with other Areas created by another.

    Subscribe For Free Demo

    22) Which filters are executed in the end?

    Ans:

    In the end “Exception Filters” are executed.

    23) Mention what are the two ways for adding constraints to a route?

    Ans:

    Two methods for adding constraints to the route is

    • Using regular expressions
    • Using an object that implements IRouteConstraint interface

    24) How can we implement validation in MVC?

    Ans:

    We can easily implement validation in MVC application by using the validators defined in the System.ComponentModel.DataAnnotations namespace. There are different types of validators as follows:

    • Required
    • DataType
    • Range
    • StringLength

    25) Mention two instances where routing is not implemented or required?

    Ans:

    Two instances where routing is not required are:

    • Programming & Frameworks Training
    • When a physical file is found that matches the URL pattern
    • When routing is disabled for a URL pattern

    26) Explain how you can implement Ajax in MVC?

    Ans:

    In MVC, Ajax can be implemented in two ways. They are as follows:

    • Ajax libraries
    • Jquery

    27) What is the use of Keep and Peek in “TempData”?

    Ans:

    Once “TempData” is read in the current request, it’s not available in the subsequent request. If we want “TempData” to be read and also available in the subsequent request then after reading we need to call “Keep” method as shown in the code below.

    28) What is WebAPI?

    Ans:

    HTTP is the most used protocol. Since many years, the browser was the most preferred client by which we consumed data exposed over HTTP. But as years passed by, client variety started spreading out. We had demanded to consume data on HTTP from clients like mobile, JavaScript, Windows applications, etc. For satisfying the broad range of clients, REST was the proposed approach. WebAPI is the technology by which you can expose data over HTTP following REST principles.

    29)How can we detect that an MVC controller is called by POST or GET?

    Ans:

    To detect if the call on the controller is a POST action or a GET action we can use the Request.HttpMethod  property as shown in the below code snippet.

    • public ActionResult SomeAction(){
    • if (Request.HttpMethod == “POST”){
    • return View(“SomePage”);
    • }
    • else{
    • return View(“SomeOtherPage”);
    • }
    • }

    30) What are the main Razor Syntax Rules

    Ans:

    Following are the rules for main Razor Syntax:

    • Razor code blocks are enclosed in @{ … }
    • Inline expressions (variables and functions) start with @
    • Code statements end with a semicolon
    • Variables are declared with the var keyword
    • Strings are enclosed with quotation marks
    • C# code is case sensitive
    • C# files have the extension .cshtml

    31) How do you implement Forms authentication in MVC?

    Ans:

    Authentication is giving access to the user for a specific service by verifying his/her identity using his/her credentials like username and password or email and password. It assures that the correct user is authenticated or logged in for a specific service and the right service has been provided to the specific user based on their role.

    32) Can you explain RenderBody and RenderPage in MVC?

    Ans:

    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 the Layout page.

    33)  What is Validation Summary in MVC?

    Ans:

    • The Validation Summary helper method generates an unordered list (UL element) of validation messages that are in the Model State Dictionary object.
    • The Validation Summary can be used to display all the error messages for all the fields. It can also be used to display custom error messages. The following figure shows how Validation Summary displays the error messages.

    34) What are Non Action methods in MVC?

    Ans:

    In MVC all public methods have been treated as Actions. So if you are creating a method and if you do not want to use it as an action method then the method has to be decorated with “NonAction” attribute as shown below –

    •  [NonAction]
    • public void TestMethod(){
    • // Method logic
    • }

    35) How to perform Exception Handling in MVC?

    Ans:

    In the controller, you can override the “OnException” event and set the “Result” to the view name which you want to invoke when an error occurs. In the below code you can see we have set the “Result” to a view named as “Error”.

    • public class HomeController : Controller{
    • protected override void OnException(ExceptionContext filterContext){
    • Exception ex = filterContext.Exception;
    • filterContext.ExceptionHandled = true;
    • var model = new HandleErrorInfo(filterContext.Exception, “Controller”,”Action”);
    • filterContext.Result = new ViewResult()
    • {
    • ViewName = “Error”,
    • ViewData = new ViewDataDictionary(model)
    • };
    • }
    • }

    36) Which is a better fit, Razor or ASPX?

    Ans:

    As per Microsoft, Razor is more preferred because it’s lightweight and has simple syntax’s.

    37) What is Code Blocks in Views?

    Ans:

    Unlike code expressions that are evaluated and sent to the response, it is the blocks of code that are executed. This is useful for declaring variables which we may be required to be used later.

    • @{
    • int x = 123;
    • string y = “aa”;
    • }

    38) Why use Html.Partial in MVC?

    Ans:

    This method is used to render the specified partial view as an HTML string. This method does not depend on any action methods. We can use this like below –

    • Course Curriculum
    • Java, J2EE & SOA Certification Training
    • Weekday / Weekend Batches
    • 1
    • @Html.Partial(“TestPartialView”)

    39) What is a glimpse?

    Ans:

    Glimpse is NuGet packages which help in finding performance, debugging and diagnostic information. Glimpse can help you get information about timelines, model binding, routes, environment, etc.

    40) How can we navigate from one view to another using a hyperlink?

    Ans:

    By using the ActionLink method you can navigate. The below code will create a simple URL which helps to navigate to the “Home” controller and invoke the Gotohome action.

    • <%= Html.ActionLink(“Home”,”Gotohome”) %>

    This brings us to the end of this article on MVC Interview Questions. Hope it helped in adding up to your knowledge. Wishing you all the best for your interview. Happy learning.

    Course Curriculum

    Take Your Career to Next Level with MVC Training to Advance Your Career

    • Instructor-led Sessions
    • Real-life Case Studies
    • Assignments
    Explore Curriculum

    41) Explain what is Model-View-Controller?

    Ans:

    MVC is a software architecture pattern for developing web application. It is handled by three objects Model-View-Controller.

    42) Mention what does Model-View-Controller represent in an MVC application?

    Ans:

    In an MVC model, Model- It represents the application data domain. In other words applications business logic is contained within the model and is responsible for maintaining data View- It represents the user interface, with which the end users communicates. In short all the user interface logic is contained within the VIEW

    Controller- It is the controller that answers to user actions. Based on the user actions, the respective controller responds within the model and choose a view to render that display the user interface. The user input logic is contained with-in the controller

    43) Explain in which assembly is the MVC framework is defined?

    Ans:

    The MVC framework is defined in System.Web.Mvc.

    44) List out few different return types of a controller action method?

    Ans:

    • View Result
    • Javascript Result
    • Redirect Result
    • Json Result
    • Content Result

    45) Mention what is the difference between adding routes, to a webform application and an MVC application?

    Ans:

    To add routes to a webform application, we can use MapPageRoute() method of the RouteCollection class, where adding routes to an MVC application, you can use MapRoute() method.

    46) Mention what are the two ways to add constraints to a route?

    Ans:

    The two methods to add constraints to a route is

    • Use regular expressions
    • Use an object that implements IRouteConstraint Interface

    47) Mention what is the advantages of MVC?

    Ans:

    • MVC segregates your project into a different segment, and it becomes easy for developers to work on
    • It is easy to edit or change some part of your project that makes project less development and maintenance cost
    • MVC makes your project more systematic

    48) Mention what “beforFilter()”,”beforeRender” and “afterFilter” functions do in Controller?

    Ans:

    beforeFilter(): This function is run before every action in the controller. It’s the right place to check for an active session or inspect user permissions.

    beforeRender(): This function is called after controller action logic, but before the view is rendered. This function is not often used, but may be required If you are calling render() manually before the end of a given action

    afterFilter(): This function is called after every controller action, and after rendering is done. It is the last controller method to run

    49) Explain the role of components Presentation, Abstraction and Control in MVC?

    Ans:

    Presentation: It is the visual representation of a specific abstraction within the application

    Abstraction: It is the business domain functionality within the application

    Control: It is a component that keeps consistency between the abstraction within the system and their presentation to the user in addition to communicating with other controls within the system

    50) Mention the advantages and disadvantages of MVC model?

    Ans:

    • It represents clear separation between business logic and presentation logic
    • Each MVC object has different responsibilities
    • The development progresses in parallel
    • Easy to manage and maintain
    • All classes and object are independent of each other
    • The model pattern is little complex
    • Inefficiency of data access in view
    • With modern user interface, it is difficult to use MVC
    • You need multiple programmers for parallel development
    • Multiple technologies knowledge is required

    51) Explain the role of “ActionFilters” in MVC?

    Ans:

    In MVC ” ActionFilters” help you to execute logic while MVC action is executed or its executing.

    52) Explain what are the steps for the execution of an MVC project?

    Ans:

    The steps for the execution of an MVC project includes

    • Performs routing
    • Creates MVC request handler
    • Create Controller
    • Execute Controller
    • Invoke action
    • Execute Result

    53) Explain what is routing? What are the three segments for routing is important?

    Ans:

    Routing helps you to decide a URL structure and map the URL with the Controller.

    • The three segments that are important for routing is
    • ControllerName
    • ActionMethodName
    • Parameter

    54) Explain how routing is done in MVC pattern?

    Ans:

    There is a group of routes called the RouteCollection, which consists of registered routes in the application. The RegisterRoutes method records the routes in this collection. A route defines a URL pattern and a handler to use if the request matches the pattern. The first parameter to the MapRoute method is the name of the route. The second parameter will be the pattern to which the URL matches. The third parameter might be the default values for the placeholders if they are not determined.

    55) Explain using hyperlink how you can navigate from one view to other view?

    Ans:

    By using “ActionLink” method as shown in the below code. The below code will make a simple URL which help to navigate to the “Home” controller and invoke the “GotoHome” action.

    Collapse / Copy Code

    • <%= Html.ActionLink(“Home”, “Gotohome”) %>

    56) Mention how can maintain session in MVC?

    Ans:

    Session can be maintained in MVC by three ways tempdata, viewdata, and viewbag.

    57) Mention what is the difference between Temp data, View, and View Bag?

    Ans:

    controller to other controller.

    View data: It helps to maintain data when you move from controller to view

    View Bag: It’s a dynamic wrapper around view data

    58) What is Output Caching in MVC?

    Ans:

    The Output cache in the ASP.NET MVC will increase the performance of your application significantly. It is used to cache the value that is returned by the controller action. So, when every time the controller action is invoked, the same value need not be generated each time. To enable the output cache, use the OutputCache attribute to the individual controller action or the entire controller class. You can also define the duration for the content to be cached in the output cache.

    59)What is Bundling and Minification in MVC?

    Ans:

    Bundling and minification are two new techniques introduced to improve request load time. It improves load time by reducing the number of requests to the server and reducing the size of requested assets (such as CSS and JavaScript).

    • Bundling: It lets us combine multiple JavaScript (.js) files or multiple cascading style sheet (.css) files so that they can be downloaded as a unit, rather than making individual HTTP requests.
    • Minification: It extracts the whitespace and performs other types of compression to make the downloaded files as small as possible. At runtime, the process recognizes the agent of the user, for example, IE, Mozilla, etc. and then removes whatever is specific to Mozilla when the request comes from IE.
    Course Curriculum

    Best MVC Course with Industry Standard Topics From Real-Time Experts

    Weekday / Weekend BatchesSee Batch Details

    60) Mention what is the difference between “ActionResult” and “ViewResult” ?

    Ans:

    “ActionResult” is an abstract class while “ViewResult” is derived from “AbstractResult” class. “ActionResult” has a number of derived classes like “JsonResult”, “FileStreamResult” and “ViewResult” .

    “ActionResult” is best if you are deriving different types of view dynamically.

    61) Explain how you can send the result back in JSON format in MVC?

    Ans:

    In order to send the result back in JSON format in MVC, you can use “JSONRESULT” class.

    62) Explain what is the difference between View and Partial View?

    Ans:

    • It contains the layout page
    • Before any view is rendered, viewstart page is rendered
    • View might have markup tags like body, html, head, title, meta etc.
    • View is not lightweight as compare to Partial View
    • It does not contain the layout page
    • Partial view does not verify for a viewstart.cshtml. We cannot put common code for a partial view within the viewStart.cshtml.page
    • Partial view is designed specially to render within the view and just because of that it does not consist any mark up
    • We can pass a regular view to the RenderPartial method

    63) List out the types of result in MVC?

    Ans:

    In MVC, there are twelve types of results in MVC where “ActionResult” class is the main class while the 11 are their sub-types

    • ViewResult
    • PartialViewResult
    • EmptyResult
    • RedirectResult
    • RedirectToRouteResult
    • JsonResult
    • JavaScriptResult
    • ContentResult
    • FileContentResult
    • FileStreamResult
    • FilePathResult

    64) Mention what is the importance of NonActionAttribute?

    Ans:

    All public methods of a controller class are treated as the action method if you want to prevent this default method then you have to assign the public method with NonActionAttribute.

    65)Mention what is the use of the default route {resource}.axd/{*pathinfo} ?

    Ans:

    This default route prevents request for a web resource file such as Webresource.axd or ScriptResource.axd from being passed to the controller.

    66) Mention the order of the filters that get executed, if the multiple filters are implemented?

    Ans:

    The filter order would be like

    • Authorization filters
    • Action filters
    • Response filters
    • Exception filters

    67) Mention what filters are executed in the end?

    Ans:

    In the end “Exception Filters” are executed.

    68) Mention what are the file extensions for razor views?

    Ans:

    For razor views the file extensions are

    • .cshtml: If C# is the programming language
    • .vbhtml: If VB is the programming language

    69) What are Route Constraints in MVC?

    Ans:

    Route constraints in the ASP.NET are used to control the behavior of the route. With route constraint, you can restrict your users to a set of URLs, or restrict browser requests to match a particular route. The route constraints are defined by using a regular expression. For eg: to set a constraint string to our hostname, we can use the routing constraint as the following. Open the RouteConfig.cs file and modify the routing entry as “abc/{controller}/{action}/{id}”. Now the URL with string “abc” as the prefix will only be able to access the site.

    70) Explain the concept of MVC Scaffolding?

    Ans:

    • ASP.NET Scaffolding is a code generation framework for ASP.NET Web applications. Visual Studio 2013 includes pre-installed code generators for MVC and Web API projects. You add scaffolding to your project when you want to quickly add code that interacts with data models. Using scaffolding can reduce the amount of time to develop standard data operations in your project.
    • Scaffolding consists of page templates, entity page templates, field page templates, and filter templates. These templates are called Scaffold templates and allow you to quickly build a functional data-driven Website.

    71) Mention what are main benefits of using MVC?

    Ans:

    There are two key benefits of using MVC

    • As the code is moved behind a separate class file, you can use the code to a great extent
    • As behind code is simply moved to.NET class, it is possible to automate UI testing. This gives an opportunity to automate manual testing and write unit tests.

    72)What is MVC in Asp.net

    Ans:

    MVC is an abbreviation for Model, View, and Controller. The MVC architectural pattern separates an application into three components – Model, View, and Controller. In this pattern, the model represents the shape of the data and business logic. It maintains and preserves the data of the application. Model objects retrieve and store model state in a database. The view is basically and technically a user interface. The view segment displays the data-using model to the user and also enables them to modify the data. The controller is the part, which handles the user request.

    73)What is MVC (Model view controller)?

    Ans:

    Model–view–controller (MVC) is a software architectural pattern for implementing user interfaces. It divides a given software application into three interconnected parts, to separate the internal representation of information from the way that information is presented to or accepted by the user.

    74)What is Razor in MVC?

    Ans:

    ASP.NET MVC has always supported the concept of “view engines” – which are the pluggable modules, which practically 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. Razor is the new view engine introduced by MVC 3.

    75) Explain attribute based routing in MVC?

    Ans:

    Routing is the process of monitoring the requests with the MVC application. In MVC, the Application_Start() event registers all the routes in the routing table. In ASP.NET MVC 5.0, a new type of routing is introduced, it is called Attribute Routing. It enables the developers to define the routing using attributes on top of the controller action method. To use the attribute routing in the MVC 5, you need to call the MapMvcAttributeRoute method. The optional parameter for the URI can be added to the route parameter using the question mark(?) in the attribute routing.

    76) What is TempData in MVC?

    Ans:

    The TempData in the ASP.NET MVC is used to store temporary data. It can be used in subsequent requests. This TempData will be cleared after the completion of the subsequent request. It is useful in transferring the non-sensitive data from one action method to another action method of the same or a different controller and redirects. It stores data as key-value pair.

    77)  Mention what is the difference between ViewData and ViewBag?

    Ans:

    In ASP.NET MVC there are three ways to pass/store data between the controllers and views.

    • ViewData is used to pass data from a controller to view.
    • It is derived from ViewDataDictionary class.
    • It is available for the current request only.
    • Requires typecasting for complex data type and checks for null values to avoid error.
    • If redirection occurs, then its value becomes null.
    • ViewBag
    MVC Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

    78) What is Route in MVC?

    Ans:

    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. A handler can also be a class that processes the request, such as a controller in an MVC application. To define a route, you create an instance of the route class by specifying the URL pattern, the handler, and optionally a name for the route.

    79)  Explain what is routing in MVC?

    Ans:

    Routing is a mechanism to process the incoming URL that is more descriptive and gives the desired response. In this case, URL is not mapped to specific files or folder, as was the case of websites in the past.

    80) What are the three segments for routing important?

    Ans:

    Routing is the URL pattern that is mapped together to a handler and is responsible for incoming browser request for a particular MVC controller. There are a total of three segments for routing that are very significant in MVC

    81) What are the Filters in MVC?

    Ans:

    The filter in ASP.NET MVC is a class that is executed before or after an action method is executed. It is a place where you can write custom logic that you want to execute. It can be executed either to an action method or a controller. It is applied in two different ways, declarative and programmatic. Applying the filter to the action or controller class is called a declarative filter. Defining the interface for the filter is called the programmatic way of applying a filter.

    82) What are Action Filters in MVC?

    Ans:

    An action filter is a type of filter in ASP.NET MVC that is executed to implement logic before and after a controller is executed. These provide an additional attribute that is applied to a section of the controller or the whole controller to modify it. These attributes are defined under System.Attribute class.

    83)  What are the types of filters?

    Ans:

    ASP.NET MVC structure upholds 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. 

    84) List the various return types of a controller action method.

    Ans:

    There is total of nine return types we can use to return results from a controller to view. The base type of all these result types is ActionResult.

    85) What is Default Route in MVC?

    Ans:

    • Default Route: The default ASP.NET MVC project templates add a generic route that uses the following URL convention to break the URL for a given request into three named segments.
    • URL: “{controller}/{action}/{id}”

    This route pattern is registered via a call to the MapRoute() extension method of RouteCollection. 

    86) What are HTML helpers in MVC?

    Ans:

    In MVC HTML Helpers is a class which are used in views to render/display HTML controls like links, TextBox, TextArea, etc.

    87) Define attribute based routing in MVC?

    Ans:

    Attribute Routing was introduced in ASP.NET MVC 5. It allows developers to generate urls for controllers actions by adding Route Attributes to them.This type of MVC routing uses attributes to define routes and gives developer more control over the urls of web application.In order to use Attribute Routing first you have to enable it by calling MapMvcAttributeRoutes during configuration.

    88) What are the Benefits of Area in MVC?

    Ans:

    • Benefits of Area in MVC
    • Allows us to organize models, views, and controllers into separate functional sections of the application, such as administration, billing, customer support and much more.
    • Easy to integrate with other Areas created by another.
    • Easy for unit testing.

    89)Explain the need of display mode in MVC?

    Ans:

    A display mode is a powerful tool for all mobile-based apps development. However, it is not limited to mobile web apps but it can also be used to display any alternative view, which is tied to an existing controller. Display Modes practically give you another level of flexibility on top of the default capabilities we saw in the last section. Display Modes can also be used along with the previous feature so the users will simply build off of the site they just created. It simplifies the ways to implement different versions of view for different devices.

    Are you looking training with Right Jobs?

    Contact Us
    Get Training Quote for Free