SOOPRO Pathshala provides ASP.NET MVC Interview Questions and Answers
MVC is a software architecture pattern for developing web application. It is handled by three objects Model-View-Controller.
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
The MVC framework is defined in System.Web.Mvc
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.
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
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
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
In MVC " ActionFilters" help you to execute logic while MVC action is executed or its executing.
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
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.
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.
@Html.ActionLink("Home", "Gotohome")
Session can be maintained in MVC by three ways tempdata, viewdata, and viewbag.
Temp data: It helps to maintain data when you shift from one 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
Partial view in MVC renders a portion of view content. It is helpful in reducing code duplication. In simple terms, partial view allows to render a view within the parent view.
In MVC, Ajax can be implemented in two ways
• Ajax libraries
• Jquery
ActionResult is an abstract class.
ViewResult is derived from AbstractResult class.
In order to send the result back in JSON format in MVC, you can use "JSONRESULT" class.
Scaffolding is a code generation framework mostly used for ASP.NET web applications.
Razor is the new view-engine introduced by MVC3, which acts as pluggable modules and applies different template syntax options.
A default route adds a generic route that utilizes the URL convention to break the URL for a given request in three segments.
The GET action type requests data from particular resources, while the POST action type submits data that needs to be processed to a specific resource.
We can implement validation in the MVC application with well-defined validators in the System.ComponentModel.DataAnnotations namespace.
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
It’s is the process of breaking the program into various distinct features which overlaps in functionality as little as possible. MVC pattern concerns on separating the content from presentation and data-processing from content.
Cookies are small text files information which is stored in the end users computer.
Keep method persist the data for the next request.
Peek = Keep + Read. It will read as well as keep the data.
Yes , Tempdata is private to a user.
Web API controller delivers data and services easily by using HTTP REST services.
ASP.NET Web Forms is a framework that follows a different pattern known as Web Forms, while ASP.NET MVC follows the MVC pattern. In Web Forms, the UI controls and code-behind files are tightly coupled, whereas in MVC, the UI is separate from the controller logic. MVC provides more control over the HTML output, supports clean URLs, and promotes testability through its separation of concerns.