Interview Questions.

Top 100+ Asp Dot Net Mvc Interview Questions And Answers

fluid

Top 100+ Asp Dot Net Mvc Interview Questions And Answers

Question 1. Breifly Explain Us What Is Asp.Net Mvc?

Answer :

ASP.Net MVC is a pattern that's used to split the software's implementation good judgment into three additives i.E. Fashions, views, and controllers.

Question 2. Tell Us Something About Model, View And Controllers In Asp.Net Mvc?

Answer :

Model : It is largely a commercial enterprise entity that's used to symbolize the application facts.

Controller : The Request that's sent by the user usually scatters via controller and it is responsibility is to redirect to the unique view using View () technique.

View : it is the presentation layer of ASP.Net MVC.

VB.NET Interview Questions
Question 3. Do You Know About The New Features In Asp.Internet Mvc 4 (asp.Internet Mvc4)?

Answer :

Following are capabilities brought newly : Mobile templates Added ASP.NET Web API template for growing REST primarily based offerings. Asynchronous controller mission assist. Bundling of the java scripts. Segregating the configs for ASP.Net MVC routing, Web API, Bundle and so forth.

Question four. How Does The 'web page Lifecycle' Of Asp.Net Mvc Works?

Answer :

Below are the processed accompanied inside the series :

App initializWhat is Separation of Concerns in ASP.NET ASP.Net MVCation
Routing
Instantiate and execute controller
Locate and invoke controller action
Instantiate and render view.
VB.NET Tutorial
Question five. Explain The Advantages Of Asp.Net Mvc Over Asp.Internet?

Answer :

Provides a smooth separation of concerns among UI (Presentation layer), version (Transfer objects/Domain Objects/Entities) and Business Logic (Controller).
Easy to UNIT Test.
Improved reusability of model and perspectives. We will have multiple perspectives that could factor to the same model and vice versa.
Improved structuring of the code.
C#. NET Interview Questions
Question 6. What Is Separation Of Concerns In Asp.Internet Asp.Net Mvc?

Answer :

It is the technique of breaking this system into various awesome features which overlaps in capability as low as possible. ASP.Net MVC sample worries on keeping apart the content material from presentation and records-processing from content.

Question 7. What Is Razor View Engine?

Answer :

Razor is the first primary replace to render HTML in ASP.Net MVC three. Razor changed into designed specifically for view engine syntax. Main recognition of this would be to simplify and code-focused templating for HTML technology.

Below is the sample of the use of Razor:

@version ASP.Net MVCMusicStore.Models.Customer

@ViewBag.Title = "Get Customers";

< div class="cust">

@Model.CustomerName
C#. NET Tutorial ASP.NET Interview Questions
Question eight. What Is The Meaning Of Unobtrusive Javascript? Explain Us By Any Practical Example?

Answer :

This is a general time period that conveys a general philosophy, much like the time period REST (Representational State Transfer). Unobtrusive JavaScript doesn't inter mix JavaScript code for your page markup. Eg : Instead of using events like onclick and onsubmit, the unobtrusive JavaScript attaches to elements with the aid of their ID or elegance based totally on the HTML5 information- attributes.

Question 9. What Is The Use Of View Model In Asp.Internet Mvc?

Answer :

View Model is a simple magnificence with homes, that's used to bind it to strongly typed view. View Model will have the validation guidelines defined for its homes the use of statistics annotations.

ADO.Net Interview Questions
Question 10. What You Mean By Routing In Asp.Net Mvc?

Answer :

Routing is a sample matching mechanism of incoming requests to the URL styles which are registered in route table. Class : "UrlRoutingModule" is used for the equal method.

ASP.NET Tutorial
Question 11. What Are Actions In Asp.Net Mvc?

Answer :

Actions are the methods in Controller elegance which is chargeable for returning the view or json statistics. Action will specially have return type : "ActionResult" and it will be invoked from technique : "InvokeAction()" referred to as by way of controller.

MVC Framework Interview Questions
Question 12. What Is Attribute Routing In Asp.Net Mvc?

Answer :

ASP.NET Web API supports this kind routing. This is added in ASP.Net MVC5. In this sort of routing, attributes are getting used to outline the routes. This kind of routing gives more manipulate over classic URI Routing.

Attribute Routing may be defined at controller degree or at Action degree like :

[Route("action = TestCategoryList")] - Controller Level

[Route("customers/TestCategoryId:int:min(10)")] - Action Level

VB.NET Interview Questions
Question 13. How To Enable Attribute Routing?

Answer :

Just upload @Model.CustomerName the method : "MapASP.Net MVCAttributeRoutes()" to enable characteristic routing as shown below:

public static void RegisterRoutes(RouteCollection routes)

    

        routes.IgnoreRoute("useful resource.Axd/*pathInfo");

        //permitting characteristic routing

        routes.MapASP.Net MVCAttributeRoutes();

        //conference-based totally routing

        routes.MapRoute

        (

            name: "Default",

            url: "controller/movement/identity",

            defaults: new  controller = "Customer", motion = "GetCustomerList", identification = UrlParameter.Optional 

        );

  

MVC Framework Tutorial
Question 14. Explain Json Binding?

Answer :

JavaScript Object Notation (JSON) binding guide began from ASP.Net MVC3 onwards through the brand new JsonValueProviderFactory, which permits the movement techniques to just accept and version-bind statistics in JSON format. This is useful in Ajax scenarios like consumer templates and data binding that want to put up records back to the server.

Question 15. Explain Dependency Resolution?

Answer :

Dependency Resolver once more has been brought in ASP.Net MVC3 and it's miles greatly simplified the usage of dependency injection in your packages. This turn to be less difficult and useful for decoupling the application additives and making them easier to check and greater configurable.

Windows Presentation Foundation(WPF) Interview Questions
Question 16. Explain Bundle.Config In Asp.Internet Mvc4?

Answer :

"BundleConfig.Cs" in ASP.Net MVC4 is used to sign up the bundles with the aid of the bundling and minification device. Many bundles are introduced through default consisting of jQuery libraries like - jquery.Validate, Modernizr, and default CSS references.

Windows Presentation Foundation(WPF) Tutorial
Question 17. How Route Table Has Been Created In Asp.Net Asp.Net Mvc?

Answer :

Method : "RegisterRoutes()" is used for registering the routes so as to be added in "Application_Start()" approach of world.Asax report, that's fired whilst the utility is loaded or commenced.

Windows CE .NET Interview Questions
Question 18. Which Are The Important Namespaces Used In Asp.Internet Mvc?

Answer :

Below are the important namespaces used in ASP.Net MVC :

System.Web.ASP.Net MVC
System.Web.ASP.Net MVC.Ajax
System.Web.ASP.Net MVC.Html
System.Web.ASP.Net MVC.Async
C#. NET Interview Questions
Question 19. What Is Viewdata?

Answer :

Viewdata incorporates the important thing, value pairs as dictionary and that is derived from magnificence : "ViewDataDictionary". In action approach we're putting the fee for viewdata and in view the cost can be fetched with the aid of typecasting.

Spring MVC Framework Tutorial
Question 20. What Is The Difference Between Viewbag And Viewdata In Asp.Net Mvc?

Answer :

ViewBag is a wrapper round ViewData, which lets in to create dynamic residences. Advantage of viewbag over viewdata will be : In ViewBag no need to typecast the objects as in ViewData. ViewBag will take gain of dynamic key-word that's added in version 4.Zero. But earlier than using ViewBag we ought to keep in mind that ViewBag is slower than ViewData.

Spring MVC Framework Interview Questions
Question 21. Explain Tempdata In Asp.Net Mvc?

Answer :

TempData is again a key, fee pair as ViewData. This is derived from "TempDataDictionary" magnificence. TempData is used while the records is to be used in two consecutive requests, this could be between the movements or between the controllers. This requires typecasting in view.

Question 22. What Are Html Helpers In Asp.Net Mvc?

Answer :

HTML Helpers are like controls in conventional web forms. But HTML helpers are greater light-weight in comparison to web controls because it does not preserve viewstate and occasions. HTML Helpers returns the HTML string which can be directly rendered to HTML web page. Custom HTML Helpers also may be created via overriding "HtmlHelper" class.

Question 23. What Are Ajax Helpers In Asp.Net Mvc?

Answer :

AJAX Helpers are used to create AJAX enabled elements like as Ajax enabled paperwork and links which performs the request asynchronously and those are extension techniques of AJAXHelper magnificence which exists in namespace - System.Web.ASP.Net MVC.

Dot Net Framework Interview Questions
Question 24. What Are The Options Can Be Configured In Ajax Helpers?

Answer :

Below are the options in AJAX helpers :

Url : This is the request URL.

Confirm : This is used to specify the message which is to be displayed in verify field.

OnBegin : Javascript method name to accept right here and this could be referred to as before the AJAX request.

OnComplete : Javascript method name to accept right here and this could be referred to as at the cease of AJAX request.

OnSuccess - Javascript technique name to be given right here and this can be known as when AJAX request is a success.

OnFailure - Javascript technique name to take delivery of right here and this can be known as whilst AJAX request is failed.

UpdateTargetId : Target element that is populated from the action returning HTML.

ASP.NET Interview Questions
Question 25. What Is Layout In Asp.Net Mvc?

Answer :

Layout pages are just like grasp pages in traditional internet paperwork. This is used to set the commonplace look across a couple of pages. In each toddler page we can locate : /p>

@

Layout = "~/Views/Shared/TestLayout1.Cshtml";

 This shows baby page makes use of TestLayout page as it's master web page.

Question 26. Explain Sections Is Asp.Net Mvc?

Answer :

Section are the a part of HTML that is to be rendered in layout page. In Layout page we can use the underneath syntax for rendering the HTML :

@RenderSection("TestSection") And in infant pages we're defining those sections as proven below :

@section TestSection

<h1>Test Content<h1>

 If any baby page does not have this section defined then blunders may be thrown to be able to avoid that we are able to render the HTML like this :

@RenderSection("TestSection", required: false)

Asp Dot Net Mvc four Interview Questions
Question 27. Can You Explain Renderbody And Renderpage In Asp.Net Mvc?

Answer :

RenderBody is like ContentPlaceHolder in internet forms. This will exist in layout web page and it'll render the kid pages/perspectives. Layout web page can have only one RenderBody() technique. RenderPage additionally exists in Layout web page and a couple of RenderPage() may be there in Layout web page.

ADO.Net Interview Questions
Question 28. What Is Viewstart Page In Asp.Net Mvc?

Answer :

This page is used to ensure commonplace layout web page may be used for a couple of views. Code written on this report might be accomplished first while software is being loaded.

Question 29. Explain The Methods Used To Render The Views In Asp.Internet Mvc?

Answer :

Below are the techniques used to render the views from motion -

View() : To go back the view from motion.

PartialView() : To go back the partial view from action.

RedirectToAction() : To Redirect to one-of-a-kind movement which may be in same controller or in unique controller.

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

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

Question 30. What Are The Sub Types Of Actionresult?

Answer :

ActionResult is used to represent the movement method end result. Below are the subtypes of ActionResult :

ViewResult
PartialViewResult
RedirectToRouteResult
RedirectResult
JavascriptResult
JSONResult
FileResult
HTTPStatusCodeResult
Question 31. What Are Non Action Methods In Asp.Net Mvc?

Answer :

In ASP.Net MVC all public methods have been dealt with as Actions. So if you are growing a method and if you do no longer want to apply it as an motion technique then the method must be decorated with "NonAction" attribute as proven under :

[NonAction]

public void TestMethod()

// Method good judgment

Question 32. How To Change The Action Name In Asp.Net Mvc?

Answer :

"ActionName" attribute may be used for converting the movement name.

Below is the pattern code snippet to illustrate greater :

[ActionName("TestActionNew")]

public ActionResult TestAction()

    

       return View();

    

So inside the above code snippet "TestAction" is the authentic movement name and in "ActionName" characteristic, name - "TestActionNew" is given. So the caller of this action method will use the call "TestActionNew" to call this motion.

Question 33. What Are Code Blocks In Views?

Answer :

Unlike code expressions that are evaluated and sent to the response, it's far the blocks of code that are performed. This is beneficial for affirming variables which we can be required to be used later.

@

 int x = 123;

 string y = "aa";

 

MVC Framework Interview Questions
Question 34. What Is The "helper Page.Isajax" Property?

Answer :

The Helper Page.IsAjax belongings receives a value that shows whether Ajax is being used in the course of the request of the Web web page.

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

Answer :

Create a JavaScript approach:

feature DrpIndexChanged()   Invoke the method:

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

Question 36. What Are Validation Annotations?

Answer :

Data annotations are attributes which may be discovered within the "System.ComponentModel.DataAnnotations" namespace. These attributes can be used for server-side validation and customer-facet validation is also supported. Four attributes - Required, String Length, Regular Expression and Range are used to cowl the commonplace validation situations.

Windows Presentation Foundation(WPF) Interview Questions
Question 37. Why To Use Html.Partial In Asp.Net Mvc?

Answer :

This method is used to render the required partial view as an HTML string. This method does no longer depend on any action methods.

We can use this like beneath :

@Html.Partial("TestPartialView")

Question 38. What Is Html.Renderpartial?

Answer :

Result of the method : "RenderPartial" is immediately written to the HTML response. This method does not go back some thing (void). This approach additionally does not depend on movement methods. RenderPartial() method calls "Write()" internally and we should make sure that "RenderPartial" approach is enclosed in the bracket. Below is the pattern code snippet : @Html.RenderPartial("TestPartialView"); 

Question 39. What Is Routeconfig.Cs In Asp.Net Mvc four?

Answer :

"RouteConfig.Cs" holds the routing configuration for ASP.Net MVC. RouteConfig may be initialized on Application_Start event registered in Global.Asax.

Question forty. What Are Scaffold Templates In Asp.Net Mvc?

Answer :

Scaffolding in ASP.NET ASP.Net MVC is used to generate the Controllers,Model and Views for create, read, update, and delete (CRUD) capability in an utility. The scaffolding could be understanding the naming conventions used for fashions and controllers and views.

Windows CE .NET Interview Questions
Question 41. Explain The Types Of Scaffoldings?

Answer :

Below are the styles of scaffoldings :

Empty
Create
Delete
Details
Edit
List
Question 42. Can A View Be Shared Across Multiple Controllers? If Yes, How We Can Do That?

Answer :

Yes we are able to share a view across a couple of controllers. We can put the view inside the "Shared" folder. When we create a brand new ASP.Net MVC Project we will see the Layout web page can be added in the shared folder, that is because it's far utilized by multiple infant pages.

Spring MVC Framework Interview Questions
Question 43. What Are The Components Required To Create A Route In Asp.Internet Mvc?

Answer :

Name - This is the name of the course.

URL Pattern : Placeholders can be given to in shape the request URL sample.

Defaults :When loading the utility which controller, movement to be loaded along side the parameter.

Question forty four. Why To Use "aid.Axd/*pathinfo" In Routing In Asp.Internet Mvc?

Answer :

Using this default course - useful resource.Axd/*pathInfo, we are able to prevent the requests for the net sources documents like - WebResource.Axd or ScriptResource.Axd from passing to a controller.

Question forty five. Can We Add Constraints To The Route? If Yes, Explain How We Can Do It?

Answer :

Yes we are able to upload constraints to route in following approaches :

Using Regular Expressions
Using item which implements interface - IRouteConstraint.
Question forty six. What Are The Possible Razor View Extensions?

Answer :

Below are the 2 kinds of extensions razor view could have :

.Cshtml : In C# programming language this extension could be used.

.Vbhtml - In VB programming language this extension can be used.

Question forty seven. What Is Partialview In Asp.Internet Mvc?

Answer :

PartialView is similar to UserControls in traditional internet paperwork. For re-usability purpose partial perspectives are used. Since it's been shared with multiple views these are saved in shared folder.

Partial Views may be rendered in following ways :

Html.Partial()
Html.RenderPartial()
Question forty eight. How We Can Add The Css In Asp.Net Mvc?

Answer :

Below is the sample code snippet to add css to razor views : < link rel="StyleSheet" href="/@Href(~Content/Site.Css")" type="text/css"/>

Question 49. Can I Add Asp.Internet Mvc Testcases In Visual Studio Express?

Answer :

No. We can not upload the take a look at cases in Visual Studio Express version it is able to be introduced simplest in Professional and Ultimate versions of Visual Studio.

Question 50. What Is The Use .Glimpse In Asp.Net Mvc?

Answer :

Glimpse is an open source tool for debugging the routes in ASP.Net MVC. It is the patron facet debugger. Glimpse has to be grew to become on by using visiting to nearby url hyperlink - http://localhost:portname//glimpse.Axd This is a famous and beneficial device for debugging which tracks the speed details, url details and many others.

Question fifty one. What Is The Need Of Action Filters In Asp.Net Mvc?

Answer :

Action Filters permit us to execute the code before or after motion has been done. This can be achieved with the aid of redecorating the movement techniques of controls with ASP.Net MVC attributes.

Question 52. Mention Some Action Filters Which Are Used Regularly In Asp.Net Mvc?

Answer :

Below are some movement filters used :

Authentication
Authorization
HandleError
OutputCache
Question fifty three. How Can We Determine Action Invoked From Http Get Or Http Post?

Answer :

This may be done in following way : Use elegance : "HttpRequestBase" and use the method : "HttpMethod" to determine the action request kind.

Question fifty four. In Server How To Check Whether Model Has Error Or Not In Asp.Net Mvc?

Answer :

This can be achieved in following way : Use class : "HttpRequestBase" and use the method : "HttpMethod" to determine the motion request kind.

Question fifty five. How To Make Sure Client Validation Is Enabled In Asp.Net Mvc?

Answer :

In Web.Config there are tags referred to as : "ClientValidationEnabled" and "UnobtrusiveJavaScriptEnabled". We can set the consumer side validation simply by way of setting those  tags "proper", then this setting might be implemented at the application stage.

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

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

Question fifty six. What Are Model Binders In Asp.Internet Mvc?

Answer :

For Model Binding we will use magnificence referred to as : "ModelBinders", which gives get right of entry to to all the model binders in an application. We can create a custom version binders by using inheriting "IModelBinder".

Question fifty seven. How We Can Handle The Exception At Controller Level In Asp.Net Mvc?

Answer :

Exception Handling is made easy in ASP.Net MVC and it could be achieved by way of simply overriding "OnException" and set the end result belongings of the filtercontext item (as shown under) to the view element, which is to be returned in case of exception.

Included overrides void OnException(ExceptionContext filterContext)

    

    

Question 58. Does Tempdata Hold The Data For Other Request In Asp.Net Mvc?

Answer :

If Tempdata is assigned within the modern-day request then it will be available for the contemporary request and the following request and it depends whether records in TempData examine or not. If records in Tempdata is read then it might no longer be to be had for the following requests.

Question fifty nine. Explain Keep Method In Tempdata In Asp.Internet Mvc?

Answer :

As explained above in case information in Tempdata has been study in present day request simplest then "Keep" approach has been used to make it to be had for the subsequent request.

@TempData["TestData"];

TempData.Keep("TestData");

Question 60. Explain Peek Method In Tempdata In Asp.Net Mvc?

Answer :

Similar to Keep approach we've one extra method known as "Peek" which is used for the same cause. This method used to read information in Tempdata and it keeps the information for next request.

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

Question sixty one. What Is Area In Asp.Net Mvc?

Answer :

Area is used to shop the info of the modules of our project. This is clearly beneficial for large packages, where controllers, perspectives and fashions are all in essential controller, view and version folders and it's far very tough to manage.

Question 62. How We Can Register The Area In Asp.Net Mvc?

Answer :

When we've created an area ensure this will be registered in "Application_Start" event in Global.Asax.

Below is the code snippet in which area registration is finished :

blanketed void Application_Start()

AreaRegistration.RegisterAllAreas();

Question sixty three. What Are Child Actions In Asp.Internet Mvc?

Answer :

To create reusable widgets toddler movements are used and this may be embedded into the determine perspectives. In ASP.Net MVC Partial views are used to have reusability in the software. Child motion specially returns the partial views.

Question sixty four. How We Can Invoke Child Actions In Asp.Net Mvc?

Answer :

"ChildActionOnly" attribute is decorated over motion techniques to signify that motion method is a baby movement. Below is the code snippet used to indicate the kid motion :

[ChildActionOnly]

public ActionResult MenuBar()

//Logic right here

go back PartialView();

Question 65. What Is Dependency Injection In Asp.Net Mvc?

Answer :

it is a layout pattern and is used for developing loosely couple code. This is significantly used in the software projects. This will lessen the coding in case of adjustments on undertaking design so that is massively used.

Question sixty six. Explain The Advantages Of Dependency Injection (di) In Asp.Internet Mvc?

Answer :

Below are the benefits of DI :

Reduces class coupling
Increases code reusing
Improves code maintainability
Improves software testing
Question sixty seven. Explain Test Driven Development (tdd) ?

Answer :

TDD is a technique which says, write your exams first earlier than you write your code. In TDD, assessments pressure your application layout and improvement cycles. You do no longer do the test-in of your code into source control till all of your unit exams pass.

Question sixty eight. Explain The Tools Used For Unit Testing In Asp.Internet Mvc?

Answer :

Below are the tools used for unit trying out :

NUnit
xUnit.NET
Ninject 2
Moq
Question 69. What Is Representational State Transfer (relaxation) Mean?

Answer :

REST is an architectural fashion which uses HTTP protocol methods like GET, POST, PUT, and DELETE to access the statistics. ASP.Net MVC works in this fashion. In ASP.Net MVC four there may be a assist for Web API which makes use of to build the provider using HTTP verbs.

Question 70. How To Use Jquery Plugins In Asp.Net Mvc Validation?

Answer :

We can use dataannotations for validation in ASP.Net MVC. If we need to apply validation for the duration of runtime the usage of Jquery then we will use Jquery plugins for validation.

Eg:

If validation is to be completed on consumer call textbox then we can do as :

$('#CustomerName').Guidelines("add", 

required: authentic,

minlength: 2,

messages: 

required: "Please input name",

minlength: "Minimum period is 2"

);

Question 71. How We Can Multiple Submit Buttons In Asp.Internet Mvc?

Answer :

Below is the scenario and the answer to solve a couple of put up buttons issue. Scenario :

@the use of (Html.BeginForm("MyTestAction","MyTestController")

    <input type="submit" value="MySave" />

    <input type="submit" value="MyEdit" />

 Solution :

Public ActionResult MyTestAction(string submit) //submit can have cost either "MySave" or "MyEdit"

    // Write code here

Question 72. What Are The Differences Between Partial View And Display Template And Edit Templates In Asp.Net Mvc?

Answer :

Display Templates : These are model centric. Meaning it depends at the homes of the view version used. It makes use of convention to be able to best show like divs or labels.

Edit Templates : These are also version centric however can have editable controls like Textboxes.

Partial View : These are view centric. These will vary from templates by way of the way they render the properties (Id's) Eg : CategoryViewModel has Product magnificence assets then it is going to be rendered as Model.Product.ProductName but in case of templates if we CategoryViewModel has List then @Html.DisplayFor(m => m.Products) works and it renders the template for each item of this list.

Question seventy three. Can I Set The Unlimited Length For "maxjsonlength" Property In Config?

Answer :

No. We can not set unlimited period for belongings maxJsonLength. Default fee is - 102400 and most cost what we are able to set might be : 2147483644.

Question 74. Can I Use Razor Code In Javascript In Asp.Internet Mvc?

Answer :

Yes. We can use the razor code in javascript in cshtml via the use of <text> detail.

< script type="text/javascript">

@foreach (var item in Model) 

< text >

//javascript goes here which makes use of the server values

< text >

< script>

Question seventy five. How Can I Return String Result From Action In Asp.Internet Mvc?

Answer :

Below is the code snippet to go back string from action approach :

public ActionResult TestAction() 

go back Content("Hello Test !!");

Question 76. How To Return The Json From Action Method In Asp.Net Mvc?

Answer :

Below is the code snippet to return string from motion technique :

public ActionResult TestAction() 

go back JSON(new  prop1 = "Test1", prop2 = "Test2" );




CFG