Match Group Frequently Asked ASP.NET MVC Interview Questions Answers

What Is The "helper Page.isajax" Property?

The Helper Page.IsAjax property gets a value that indicates whether Ajax is being used during the request of the Web page.

Can You Explain Renderbody And Renderpage In Asp.net Mvc?

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

What Is Viewstart Page In Asp.net Mvc?

This page is used to make sure common layout page will be used for multiple views. Code written in this file will be executed first when application is being loaded.

Explain The Methods Used To Render The Views In Asp.net Mvc?

Below are the methods used to render the views from action -

View() : To return the view from action.

PartialView() : To return the partial view from action.

RedirectToAction() : To Redirect to different action which can be in same controller or in different controller.

Redirect() : Similar to "Response.Redirect()" in webforms, used to redirect to specified URL.

RedirectToRoute() : Redirect to action from the specified URL but URL in the route table has been matched.

What Are The Sub Types Of Actionresult?

ActionResult is used to represent the action method result. Below are the subtypes of ActionResult

ViewResult
PartialViewResult
RedirectToRouteResult
RedirectResult
JavascriptResult
JSONResult
FileResult
HTTPStatusCodeResult
Match Group Frequently Asked ASP.NET MVC Interview Questions Answers
Match Group Frequently Asked ASP.NET MVC Interview Questions Answers

What Are Non Action Methods In Asp.net Mvc?

In ASP.Net 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

}

How We Can Call A Javascript Function On The Change Of A Dropdown List In Asp.net Mvc?

Create a JavaScript method

function DrpIndexChanged() { } Invoke the method

< %:Html.DropDownListFor(x => x.SelectedProduct, new SelectList(Model.Customers, "Value", "Text"), "Please Select a Customer", new { id = "ddlCustomers", onchange=" DrpIndexChanged ()" })%>

What Are Validation Annotations?

Data annotations are attributes which can be found in the "System.ComponentModel.DataAnnotations" namespace. These attributes will be used for server-side validation and client-side validation is also supported. Four attributes - Required, String Length, Regular Expression and Range are used to cover the common validation scenarios.

Why To Use Html.partial In Asp.net Mvc?

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

@Html.Partial("TestPartialView")

What Is The Need Of Action Filters In Asp.net Mvc?

Action Filters allow us to execute the code before or after action has been executed. This can be done by decorating the action methods of controls with ASP.Net MVC attributes.

Mention Some Action Filters Which Are Used Regularly In Asp.net Mvc?

Below are some action filters used

Authentication
Authorization
HandleError
OutputCache

How Can We Determine Action Invoked From Http Get Or Http Post?

This can be done in following way : Use class : "HttpRequestBase" and use the method : "HttpMethod" to determine the action request type.

In Server How To Check Whether Model Has Error Or Not In Asp.net Mvc?

This can be done in following way : Use class : "HttpRequestBase" and use the method : "HttpMethod" to determine the action request type.

How To Make Sure Client Validation Is Enabled In Asp.net Mvc?

In Web.Config there are tags called : "ClientValidationEnabled" and "UnobtrusiveJavaScriptEnabled". We can set the client side validation just by setting these two tags "true", then this setting will be applied at the application level.

< add key="ClientValidationEnabled" value="true" />

< add key="UnobtrusiveJavaScriptEnabled" value="true" />

What Is Html.renderpartial?

Result of the method : "RenderPartial" is directly written to the HTML response. This method does not return anything (void). This method also does not depend on action methods. RenderPartial() method calls "Write()" internally and we have to make sure that "RenderPartial" method is enclosed in the bracket. Below is the sample code snippet : @{Html.RenderPartial("TestPartialView"); }

What Is Routeconfig.cs In Asp.net Mvc 4?

"RouteConfig.cs" holds the routing configuration for ASP.Net MVC. RouteConfig will be initialized on Application_Start event registered in Global.asax.

What Are Scaffold Templates In Asp.net Mvc?

Scaffolding in ASP.NET 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 ASP.Net 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 Are The Components Required To Create A Route In Asp.net Mvc?

Name - This is the name of the route.

URL Pattern : Placeholders will be given to match the request URL pattern.

Defaults :When loading the application which controller, action to be loaded along with the parameter.

Why To Use "{resource}.axd/{*pathinfo}" In Routing In Asp.net Mvc?

Using this default route - {resource}.axd/{*pathInfo}, we can prevent the requests for the web resources files like - WebResource.axd or ScriptResource.axd from passing to a controller.

Can We Add Constraints To The Route? If Yes, Explain How We Can Do It?

Yes we can add constraints to route in following ways

Using Regular Expressions
Using object which implements interface - IRouteConstraint.

What Are The Possible Razor View Extensions?

Below are the two types of extensions razor view can have

.cshtml : In C# programming language this extension will be used.

.vbhtml - In VB programming language this extension will be used.

What Is Partialview In Asp.net Mvc?

PartialView is similar to UserControls in traditional web forms. For re-usability purpose partial views are used. Since it's been shared with multiple views these are kept in shared folder.

Partial Views can be rendered in following ways

Html.Partial()
Html.RenderPartial()

How We Can Add The Css In Asp.net 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 Asp.net 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 Asp.net Mvc?

Glimpse is an open source tool for debugging the routes in ASP.Net 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 Are Model Binders In Asp.net Mvc?

For Model Binding we will use class called : "ModelBinders", which gives access to all the model binders in an application. We can create a custom model binders by inheriting "IModelBinder".

How We Can Handle The Exception At Controller Level In Asp.net Mvc?

Exception Handling is made simple in ASP.Net MVC and it can be done by just overriding "OnException" and set the result property of the filtercontext object (as shown below) to the view detail, which is to be returned in case of exception.

protected overrides void OnException(ExceptionContext filterContext)

    {

    }

How We Can Invoke Child Actions In Asp.net Mvc?

"ChildActionOnly" attribute is decorated over action methods to indicate that action method is a child action. Below is the code snippet used to denote the child action

[ChildActionOnly]

public ActionResult MenuBar()

{

//Logic here

return PartialView();

}

What Is Dependency Injection In Asp.net Mvc?

it's a design pattern and is used for developing loosely couple code. This is greatly used in the software projects. This will reduce the coding in case of changes on project design so this is vastly used.

Explain The Advantages Of Dependency Injection (di) In Asp.net Mvc?

Below are the advantages of DI

Reduces class coupling
Increases code reusing
Improves code maintainability
Improves application testing

Does Tempdata Hold The Data For Other Request In Asp.net Mvc?

If Tempdata is assigned in the current request then it will be available for the current request and the subsequent request and it depends whether data in TempData read or not. If data in Tempdata is read then it would not be available for the subsequent requests.

Explain Keep Method In Tempdata In Asp.net Mvc?

As explained above in case data in Tempdata has been read in current request only then "Keep" method has been used to make it available for the subsequent request.

@TempData["TestData"];

TempData.Keep("TestData");

Explain Peek Method In Tempdata In Asp.net Mvc?

Similar to Keep method we have one more method called "Peek" which is used for the same purpose. This method used to read data in Tempdata and it maintains the data for subsequent request.

string A4str = TempData.Peek("TT").ToString();

What Is Area In Asp.net Mvc?

Area is used to store the details of the modules of our project. This is really helpful for big applications, where controllers, views and models are all in main controller, view and model folders and it is very difficult to manage.

How We Can Register The Area In Asp.net Mvc?

When we have created an area make sure this will be registered in "Application_Start" event in Global.asax.

Below is the code snippet where area registration is done

protected void Application_Start()

{

AreaRegistration.RegisterAllAreas();

}

What Are Child Actions In Asp.net Mvc?

To create reusable widgets child actions are used and this will be embedded into the parent views. In ASP.Net MVC Partial views are used to have reusability in the application. Child action mainly returns the partial views.

Explain Test Driven Development (tdd) ?

TDD is a methodology which says, write your tests first before you write your code. In TDD, tests drive your application design and development cycles. You do not do the check-in of your code into source control until all of your unit tests pass.

Post a Comment

Previous Post Next Post