Mention what does Model-View-Controller represent in an MVC application?
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
Explain in which assembly is the MVC framework is defined?
The MVC framework is defined in System.Web.Mvc.
Explain what is routing? What are the three segments for routing is important?
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
Mention what is the difference between “ActionResult” and “ViewResult” ?
“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.
Explain how you can send the result back in JSON format in MVC?
In order to send the result back in JSON format in MVC, you can use “JSONRESULT” class.
List out the types of result in MVC?
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
Mention what is the importance of NonActionAttribute?
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.
Mention what is the use of the default route {resource}.axd/{*pathinfo} ?
This default route prevents request for a web resource file such as Webresource.axd or ScriptResource.axd from being passed to the controller.
Mention the order of the filters that get executed, if the multiple filters are implemented?
The filter order would be like
Authorization filters
Action filters
Response filters
Exception filters
What is ASP.NET MVC?
ASP.NET MVC is a web application Framework. It is light weight and highly testable Framework. MVC separates application into three components — Model, View and Controller.
What is Razor View Engine?
Razor is the first major update to render HTML in MVC 3. Razor was designed specifically for view engine syntax. Main focus of this would be to simplify and code-focused templating for HTML generation. Below is the sample of using Razor:
@model MvcMusicStore.Models.Customer
@{ViewBag.Title = “Get Customers”;}
<div class=”cust”> <h3><em>@Model.CustomerName</em> </h3>
What you mean by Routing in MVC?
Routing is a pattern matching mechanism of incoming requests to the URL patterns which are registered in route table. Class — “UrlRoutingModule” is used for the same process.
What are Actions in MVC?
Actions are the methods in Controller class which is responsible for returning the view or json data. Action will mainly have return type — “ActionResult” and it will be invoked from method — “InvokeAction()” called by controller.
What is Attribute Routing in MVC?
ASP.NET Web API supports this type routing. This is introduced in MVC5. In this type of routing, attributes are being used to define the routes. This type of routing gives more control over classic URI Routing. Attribute Routing can be defined at controller level or at Action level like –
[Route(“{action = TestCategoryList}”)] — Controller Level
[Route(“customers/{TestCategoryId:int:min(10)}”)] — Action Level
How to enable Attribute Routing?
Just add the method — “MapMvcAttributeRoutes()” to enable attribute routing as shown below
public static void RegistearRoutes(RouteCollection routes)
{
routes.IgnoareRoute(“{resource}.axd/{*pathInfo}”);
//enabling attribute routing
routes.MapMvcAttributeRoutes();
//convention-based routing
routes.MapRoute
(
name: “Default”,
url: “{controller}/{action}/{id}”,
defaults: new { controller = “Customer”, action = “GetCustomerList”, id = UrlParameter.Optional }
);
}
Can you explain Model, Controller and View in MVC?
Model — It’s a business entity and it is used to represent the application data.
Controller — Request sent by the user always scatters through controller and it’s responsibility is to redirect to the specific view using View() method.
View — It’s the presentation layer of MVC.
Explain the new features added in version 4 of MVC (MVC4)?
Following are features added newly –
→Asynchronous controller task support.
→Bundling the java scripts.
→Segregating the configs for MVC routing, Web API, Bundle etc.
→Mobile templates
→Added ASP.NET Web API template for creating REST based services.
→Asynchronous controller task support.
→Bundling the java scripts.
→Segregating the configs for MVC routing, Web API, Bundle etc.
Can you explain the page life cycle of MVC?
Below are the processed followed in the sequence -
→App initialization
→Routing
→Instantiate and execute controller
→Locate and invoke controller action
→Instantiate and render view.
What are the advantages of MVC over ASP.NET?
→Provides a clean separation of concerns among UI (Presentation layer), model (Transfer objects/Domain Objects/Entities) and Business Logic (Controller).
→Easy to UNIT Test.
→Improved reusability of model and views. We can have multiple views which can point to the same model and vice versa.
→Improved structuring of the code.
What is Separation of Concerns in ASP.NET MVC?
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.
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
Explain in which assembly is the MVC framework is defined?
The MVC framework is defined in System.Web.Mvc.
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
Mention what is the difference between “ActionResult” and “ViewResult” ?
“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.
Explain how you can send the result back in JSON format in MVC?
In order to send the result back in JSON format in MVC, you can use “JSONRESULT” class.
Capgemini Frequently Asked ASP.NET MVC Interview Questions Answers |
List out the types of result in MVC?
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
Mention what is the importance of NonActionAttribute?
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.
Mention what is the use of the default route {resource}.axd/{*pathinfo} ?
This default route prevents request for a web resource file such as Webresource.axd or ScriptResource.axd from being passed to the controller.
Mention the order of the filters that get executed, if the multiple filters are implemented?
The filter order would be like
Authorization filters
Action filters
Response filters
Exception filters
Explain how routing is done in MVC pattern?
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.
Explain using hyperlink how you can navigate from one view to other view?
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”) %>
Mention what filters are executed in the end?
In the end “Exception Filters” are executed.
Mention what are the file extensions for razor views?
For razor views the file extensions are
.cshtml: If C# is the programming language
.vbhtml: If VB is the programming language
Mention what are the two ways for adding constraints to a route?
Two methods for adding constraints to route is
Using regular expressions
Using an object that implements IRouteConstraint interface
Mention how can maintain session in MVC?
Session can be maintained in MVC by three ways tempdata, viewdata, and viewbag.
Mention what is the difference between Temp data, View, and View Bag?
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
What is partial view in MVC?
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.
Explain how you can implement Ajax in MVC?
In Ajax, MVC can be implemented in two ways
Ajax libraries
Jquery.
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.
Explain using hyperlink how you can navigate from one view to other view?
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”) %>
Mention what filters are executed in the end?
In the end “Exception Filters” are executed.
Mention what are the file extensions for razor views?
For razor views the file extensions are
.cshtml: If C# is the programming language
.vbhtml: If VB is the programming language
Mention what are the two ways for adding constraints to a route?
Two methods for adding constraints to route is
Using regular expressions
Using an object that implements IRouteConstraint interface
Mention how can maintain session in MVC?
Session can be maintained in MVC by three ways tempdata, viewdata, and viewbag.
Mention what is the difference between Temp data, View, and View Bag?
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
What is partial view in MVC?
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.
Explain how you can implement Ajax in MVC?
In Ajax, MVC can be implemented in two ways
Ajax libraries
Jquery.
What is ASP.NET MVC?
ASP.NET MVC is a web application Framework. It is light weight and highly testable Framework. MVC separates application into three components — Model, View and Controller.
What is Razor View Engine?
Razor is the first major update to render HTML in MVC 3. Razor was designed specifically for view engine syntax. Main focus of this would be to simplify and code-focused templating for HTML generation. Below is the sample of using Razor:
@model MvcMusicStore.Models.Customer
@{ViewBag.Title = “Get Customers”;}
<div class=”cust”> <h3><em>@Model.CustomerName</em> </h3>
What you mean by Routing in MVC?
Routing is a pattern matching mechanism of incoming requests to the URL patterns which are registered in route table. Class — “UrlRoutingModule” is used for the same process.
What are Actions in MVC?
Actions are the methods in Controller class which is responsible for returning the view or json data. Action will mainly have return type — “ActionResult” and it will be invoked from method — “InvokeAction()” called by controller.
What is Attribute Routing in MVC?
ASP.NET Web API supports this type routing. This is introduced in MVC5. In this type of routing, attributes are being used to define the routes. This type of routing gives more control over classic URI Routing. Attribute Routing can be defined at controller level or at Action level like –
[Route(“{action = TestCategoryList}”)] — Controller Level
[Route(“customers/{TestCategoryId:int:min(10)}”)] — Action Level
How to enable Attribute Routing?
Just add the method — “MapMvcAttributeRoutes()” to enable attribute routing as shown below
public static void RegistearRoutes(RouteCollection routes)
{
routes.IgnoareRoute(“{resource}.axd/{*pathInfo}”);
//enabling attribute routing
routes.MapMvcAttributeRoutes();
//convention-based routing
routes.MapRoute
(
name: “Default”,
url: “{controller}/{action}/{id}”,
defaults: new { controller = “Customer”, action = “GetCustomerList”, id = UrlParameter.Optional }
);
}
Can you explain Model, Controller and View in MVC?
Model — It’s a business entity and it is used to represent the application data.
Controller — Request sent by the user always scatters through controller and it’s responsibility is to redirect to the specific view using View() method.
View — It’s the presentation layer of MVC.
Explain the new features added in version 4 of MVC (MVC4)?
Following are features added newly –
→Asynchronous controller task support.
→Bundling the java scripts.
→Segregating the configs for MVC routing, Web API, Bundle etc.
→Mobile templates
→Added ASP.NET Web API template for creating REST based services.
→Asynchronous controller task support.
→Bundling the java scripts.
→Segregating the configs for MVC routing, Web API, Bundle etc.
Can you explain the page life cycle of MVC?
Below are the processed followed in the sequence -
→App initialization
→Routing
→Instantiate and execute controller
→Locate and invoke controller action
→Instantiate and render view.
What are the advantages of MVC over ASP.NET?
→Provides a clean separation of concerns among UI (Presentation layer), model (Transfer objects/Domain Objects/Entities) and Business Logic (Controller).
→Easy to UNIT Test.
→Improved reusability of model and views. We can have multiple views which can point to the same model and vice versa.
→Improved structuring of the code.
What is Separation of Concerns in ASP.NET MVC?
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.
How we can add the CSS in MVC?
Below is the sample code snippet to add css to razor views –
<link rel=”StyleSheet” href=”/@Href(~Content/Site.css”)” type=”text/css”/>
Can I add MVC Testcases in Visual Studio Express?
No. We cannot add the test cases in Visual Studio Express edition it can be added only in Professional and Ultimate versions of Visual Studio.
What is the use .Glimpse in MVC?
Glimpse is an open source tool for debugging the routes in MVC. It is the client side debugger. Glimpse has to be turned on by visiting to local url link -
http://localhost:portname//glimpse.axd
This is a popular and useful tool for debugging which tracks the speed details, url details etc.
What is RouteConfig.cs in MVC 4?
“RouteConfig.cs” holds the routing configuration for MVC. RouteConfig will be initialized on Application_Start event registered in Global.asax.
What are Scaffold templates in MVC?
Scaffolding in ASP.NET MVC is used to generate the Controllers,Model and Views for create, read, update, and delete (CRUD) functionality in an application. The scaffolding will be knowing the naming conventions used for models and controllers and views.
Explain the types of Scaffoldings.
Below are the types of scaffoldings –
Empty
Create
Delete
Details
Edit
List
Below is the sample code snippet to add css to razor views –
<link rel=”StyleSheet” href=”/@Href(~Content/Site.css”)” type=”text/css”/>
Can I add MVC Testcases in Visual Studio Express?
No. We cannot add the test cases in Visual Studio Express edition it can be added only in Professional and Ultimate versions of Visual Studio.
What is the use .Glimpse in MVC?
Glimpse is an open source tool for debugging the routes in MVC. It is the client side debugger. Glimpse has to be turned on by visiting to local url link -
http://localhost:portname//glimpse.axd
This is a popular and useful tool for debugging which tracks the speed details, url details etc.
What is RouteConfig.cs in MVC 4?
“RouteConfig.cs” holds the routing configuration for MVC. RouteConfig will be initialized on Application_Start event registered in Global.asax.
What are Scaffold templates in MVC?
Scaffolding in ASP.NET MVC is used to generate the Controllers,Model and Views for create, read, update, and delete (CRUD) functionality in an application. The scaffolding will be knowing the naming conventions used for models and controllers and views.
Explain the types of Scaffoldings.
Below are the types of scaffoldings –
Empty
Create
Delete
Details
Edit
List
Post a Comment