January 14, 2019

Srikaanth

Daum Frequently Asked ASP.NET MVC Interview Questions Answers

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
Daum Frequently Asked ASP.NET MVC Interview Questions Answers
Daum Frequently Asked ASP.NET MVC Interview Questions Answers

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

Can a view be shared across multiple controllers? If Yes, How we can do that?

Yes, we can share a view across multiple controllers. We can put the view in the “Shared” folder. When we create a new MVC Project we can see the Layout page will be added in the shared folder, which is because it is used by multiple child pages.

What is the difference between ViewBag and ViewData in MVC?

ViewBag is a wrapper around ViewData, which allows to create dynamic properties. Advantage of viewbag over viewdata will be –

In ViewBag no need to typecast the objects as in ViewData.

ViewBag will take advantage of dynamic keyword which is introduced in version 4.0. But before using ViewBag we have to keep in mind that ViewBag is slower than ViewData.

https://mytecbooks.blogspot.com/2019/01/daum-frequently-asked-aspnet-mvc.html
Subscribe to get more Posts :