InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
How We Can Override The Action Names In Mvc? |
|
Answer» If we WANT to override the ACTION names we can do like this: [ActionName("NewActionName")] public ACTIONRESULT TestAction() { return View(); } If we want to override the action names we can do like this: [ActionName("NewActionName")] public ActionResult TestAction() { return View(); } |
|
| 2. |
How To Return The Json From Action Method In Mvc? |
|
Answer» Below is the code snippet to RETURN string from ACTION method: public ActionResult TestAction() { return JSON(NEW { prop1 = “Test1”, PROP2 = “TEST2” }); } Below is the code snippet to return string from action method: public ActionResult TestAction() { return JSON(new { prop1 = “Test1”, prop2 = “Test2” }); } |
|
| 3. |
How Can I Return String Result From Action In Mvc? |
|
Answer» Below is the code snippet to RETURN string from action method: public ACTIONRESULT TestAction() { return Content("HELLO Test !!"); } Below is the code snippet to return string from action method: public ActionResult TestAction() { return Content("Hello Test !!"); } |
|
| 4. |
Can I Use Razor Code In Javascript In Mvc? |
|
Answer» Yes. We can use the RAZOR code in JAVASCRIPT in cshtml by<text>usingelement. <script type="text/javascript"> @foreach (VAR ITEM in Model) { <text> //javascript goes here which uses the server values </text> } </script> Yes. We can use the razor code in javascript in cshtml by<text>usingelement. <script type="text/javascript"> @foreach (var item in Model) { <text> //javascript goes here which uses the server values </text> } </script> |
|
| 5. |
Can I Set The Unlimited Length For “maxjsonlength” Property In Config? |
|
Answer» No. We can’t SET UNLIMITED length for property maxJsonLength. Default value is - 102400 and MAXIMUM value what we can set would be – 2147483644. No. We can’t set unlimited length for property maxJsonLength. Default value is - 102400 and maximum value what we can set would be – 2147483644. |
|
| 6. |
What Are The Differences Between Partial View And Display Template And Edit Templates In Mvc? |
Answer»
|
|
| 7. |
How To Use Jquery Plugins In Mvc Validation? |
|
Answer» We can use dataannotations for validation in MVC. If we want to use validation during runtime using Jquery then we can use Jquery plugins for validation. Eg: If validation is to be DONE on customer name TEXTBOX then we can do as – $('#CustomerName').RULES("add", { required: true, minlength: 2, messages: { required: "Please enter name", minlength: "Minimum LENGTH is 2" } }); We can use dataannotations for validation in MVC. If we want to use validation during runtime using Jquery then we can use Jquery plugins for validation. Eg: If validation is to be done on customer name textbox then we can do as – $('#CustomerName').rules("add", { required: true, minlength: 2, messages: { required: "Please enter name", minlength: "Minimum length is 2" } }); |
|
| 8. |
Explain The Tools Used For Unit Testing In Mvc? |
|
Answer» Below are the TOOLS USED for unit testing: Below are the tools used for unit testing: |
|
| 9. |
Explain The Advantages Of Dependency Injection (di) In Mvc? |
|
Answer» Below are the ADVANTAGES of DI:
Below are the advantages of DI: |
|
| 10. |
What Is Dependency Injection In Mvc? |
|
Answer» 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. 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. |
|
| 11. |
How We Can Invoke Child Actions In Mvc? |
|
Answer» “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(); } “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(); } |
|
| 12. |
What Are Child Actions In Mvc? |
|
Answer» To create reusable widgets child ACTIONS are USED and this will be embedded into the parent VIEWS. In MVC PARTIAL views are used to have reusability in the application. Child ACTION mainly returns the partial views. To create reusable widgets child actions are used and this will be embedded into the parent views. In MVC Partial views are used to have reusability in the application. Child action mainly returns the partial views. |
|
| 13. |
How We Can Register The Area In Mvc? |
|
Answer» 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(); } 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(); } |
|
| 14. |
What Is Area In Mvc? |
|
Answer» 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. 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. |
|
| 15. |
Explain Peek Method In Tempdata In Mvc? |
|
Answer» 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(); 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(); |
|
| 16. |
Explain Keep Method In Tempdata In Mvc? |
|
Answer» 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”); 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”); |
|
| 17. |
Does Tempdata Hold The Data For Other Request In Mvc? |
|
Answer» 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. 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. |
|
| 18. |
How We Can Handle The Exception At Controller Level In Mvc? |
|
Answer» Exception HANDLING is made SIMPLE in 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) { } Exception Handling is made simple in 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) { } |
|
| 19. |
What Are Model Binders In Mvc? |
|
Answer» 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”. 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”. |
|
| 20. |
How To Make Sure Client Validation Is Enabled In Mvc? |
|
Answer» 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" />
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" />
|
|
| 21. |
In Server How To Check Whether Model Has Error Or Not In Mvc? |
|
Answer» Whenever VALIDATION fails it will be TRACKED in ModelState. By using property – ISVALID it can be determined. In Server code, check LIKE this – if(ModelState.IsValid){ // No Validation Errors } Whenever validation fails it will be tracked in ModelState. By using property – IsValid it can be determined. In Server code, check like this – if(ModelState.IsValid){ // No Validation Errors } |
|
| 22. |
Mention Some Action Filters Which Are Used Regularly In Mvc? |
|
Answer» Below are some ACTION filters USED:
Below are some action filters used: |
|
| 23. |
What Is The Need Of Action Filters In Mvc? |
|
Answer» 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 MVC attributes. 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 MVC attributes. |
|
| 24. |
What Is The Use .glimpse In Mvc? |
|
Answer» 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 -
This is a popular and USEFUL tool for debugging which tracks the speed details, url details etc. 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 - This is a popular and useful tool for debugging which tracks the speed details, url details etc. |
|
| 25. |
Can I Add Mvc Test Cases In Visual Studio Express? |
|
Answer» 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. 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. |
|
| 26. |
How We Can Add The Css In 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"/> Below is the sample code snippet to add css to razor views: <link rel="StyleSheet" href="/@Href(~Content/Site.css")" type="text/css"/> |
|
| 27. |
Why To Use “{resource}.axd/{*pathinfo}” In Routing In Mvc? |
|
Answer» 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. 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. |
|
| 28. |
What Are The Components Required To Create A Route In Mvc? |
Answer»
|
|
| 29. |
Explain The Types Of Scaffoldings. |
|
Answer» Below are the TYPES of scaffoldings:
Below are the types of scaffoldings: |
|
| 30. |
What Are Scaffold Templates In Mvc? |
|
Answer» 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. 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. |
|
| 31. |
What Is Routeconfig.cs In Mvc 4? |
|
Answer» "RouteConfig.cs" holds the routing CONFIGURATION for MVC. RouteConfig will be initialized on Application_Start EVENT registered in Global.asax. "RouteConfig.cs" holds the routing configuration for MVC. RouteConfig will be initialized on Application_Start event registered in Global.asax. |
|
| 32. |
Why To Use Html.partial In Mvc? |
|
Answer» 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") 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") |
|
| 33. |
How We Can Call A Javascript Function On The Change Of A Dropdown List In Mvc? |
|
Answer» Create a JavaScript METHOD: Invoke the method: <%:Html.DropDownListFor(X => x.SelectedProduct, new SelectList(Model.Customers, "VALUE", "Text"), "PLEASE SELECT a Customer", new { id = "ddlCustomers", onchange=" DrpIndexChanged ()" })%> Create a JavaScript method: Invoke the method: <%:Html.DropDownListFor(x => x.SelectedProduct, new SelectList(Model.Customers, "Value", "Text"), "Please Select a Customer", new { id = "ddlCustomers", onchange=" DrpIndexChanged ()" })%> |
|
| 34. |
What Is The "helperpage.isajax" Property? |
|
Answer» The HelperPage.IsAjax PROPERTY gets a value that INDICATES whether Ajax is being used during the request of the Web page. The HelperPage.IsAjax property gets a value that indicates whether Ajax is being used during the request of the Web page. |
|
| 35. |
How To Change The Action Name In Mvc? |
|
Answer» “ActionName” ATTRIBUTE can be used for changing the action name. Below is the sample CODE snippet to DEMONSTRATE more: [ActionName("TestActionNew")] PUBLIC ActionResult TestAction() { return View(); } So in the above code snippet “TestAction” is the ORIGINAL action name and in “ActionName” attribute, name - “TestActionNew” is given. So the caller of this action method will use the name “TestActionNew” to call this action. “ActionName” attribute can be used for changing the action name. Below is the sample code snippet to demonstrate more: [ActionName("TestActionNew")] public ActionResult TestAction() { return View(); } So in the above code snippet “TestAction” is the original action name and in “ActionName” attribute, name - “TestActionNew” is given. So the caller of this action method will use the name “TestActionNew” to call this action. |
|
| 36. |
What Are Non Action Methods In Mvc? |
|
Answer» 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 as shown below – [NonAction] public void TestMethod() { // Method LOGIC } 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 as shown below – [NonAction] public void TestMethod() { // Method logic } |
|
| 37. |
Explain The Methods Used To Render The Views In Mvc? |
|
Answer» Below are the methods USED to render the views from action:
Below are the methods used to render the views from action: |
|
| 38. |
What Is Viewstart Page In Mvc? |
|
Answer» 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. 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. |
|
| 39. |
Can You Explain Renderbody And Renderpage In Mvc? |
|
Answer» 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. 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. |
|
| 40. |
Explain Sections Is Mvc? |
|
Answer» SECTION are the part of HTML which is to be rendered in layout page. In Layout page we will use the below syntax for rendering the HTML – @RenderSection("TestSection") And in child PAGES we are defining these sections as shown below – @section TestSection{ TEST CONTENT} If any child page does not have this section defined then error will be thrown so to avoid that we can render the HTML LIKE this – @RenderSection("TestSection", required: false) Section are the part of HTML which is to be rendered in layout page. In Layout page we will use the below syntax for rendering the HTML – @RenderSection("TestSection") And in child pages we are defining these sections as shown below – @section TestSection{ } If any child page does not have this section defined then error will be thrown so to avoid that we can render the HTML like this – @RenderSection("TestSection", required: false) |
|
| 41. |
What Is Layout In Mvc? |
|
Answer» Layout pages are SIMILAR to master pages in traditional web forms. This is USED to set the common LOOK across MULTIPLE pages. In each child page we can FIND – /p> @{ Layout = "~/Views/Shared/TestLayout1.cshtml"; } This indicates child page uses TestLayout page as it’s master page. Layout pages are similar to master pages in traditional web forms. This is used to set the common look across multiple pages. In each child page we can find – /p> @{ Layout = "~/Views/Shared/TestLayout1.cshtml"; } This indicates child page uses TestLayout page as it’s master page. |
|
| 42. |
What Are Ajax Helpers In Mvc? |
|
Answer» AJAX Helpers are used to create AJAX enabled elements LIKE as Ajax enabled FORMS and links which PERFORMS the request asynchronously and these are EXTENSION methods of AJAXHelper class which exists in namespace - System.Web.Mvc. AJAX Helpers are used to create AJAX enabled elements like as Ajax enabled forms and links which performs the request asynchronously and these are extension methods of AJAXHelper class which exists in namespace - System.Web.Mvc. |
|
| 43. |
What Are Html Helpers In Mvc? |
Answer»
|
|
| 44. |
Explain Tempdata In Mvc? |
|
Answer» TEMPDATA is again a key, value pair as VIEWDATA. This is derived from “TempDataDictionary” class. TempData is used when the data is to be used in two CONSECUTIVE requests, this COULD be between the actions or between the controllers. This requires typecasting in VIEW. TempData is again a key, value pair as ViewData. This is derived from “TempDataDictionary” class. TempData is used when the data is to be used in two consecutive requests, this could be between the actions or between the controllers. This requires typecasting in view. |
|
| 45. |
What Is The Difference Between Viewbag And Viewdata In Mvc? |
|
Answer» ViewBag is a wrapper around ViewData, which allows to create dynamic properties. ADVANTAGE of viewbag over viewdata will be:
in VERSION 4.0. But before USING ViewBag we have to keep in MIND that ViewBag is slower than ViewData. ViewBag is a wrapper around ViewData, which allows to create dynamic properties. Advantage of viewbag over viewdata will be: in version 4.0. But before using ViewBag we have to keep in mind that ViewBag is slower than ViewData. |
|
| 46. |
Which Are The Important Namespaces Used In Mvc? |
|
Answer» Below are the IMPORTANT NAMESPACES USED in MVC:
Below are the important namespaces used in MVC: |
|
| 47. |
How Route Table Has Been Created In Asp.net Mvc? |
|
Answer» Method – “RegisterRoutes()” is used for REGISTERING the routes which will be added in “Application_Start()” method of global.asax FILE, which is FIRED when the application is loaded or STARTED. Method – “RegisterRoutes()” is used for registering the routes which will be added in “Application_Start()” method of global.asax file, which is fired when the application is loaded or started. |
|
| 48. |
Explain Bundle.config In Mvc 4? |
|
Answer» "BundleConfig.cs" in MVC4 is used to register the bundles by the bundling and MINIFICATION system. Many bundles are ADDED by default including JQUERY libraries like - jquery.validate, MODERNIZR, and default CSS references. "BundleConfig.cs" in MVC4 is used to register the bundles by the bundling and minification system. Many bundles are added by default including jQuery libraries like - jquery.validate, Modernizr, and default CSS references. |
|
| 49. |
What Is Attribute Routing In Mvc? |
|
Answer» 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 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 |
|
| 50. |
What Are Actions In Mvc? |
|
Answer» 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. 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. |
|