This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
How To Return The Json From Action Method In Asp.net 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" }); } |
|
| 2. |
How Can I Return String Result From Action In Asp.net 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 !!"); } |
|
| 3. |
Can I Use Razor Code In Javascript In Asp.net Mvc? |
|
Answer» Yes. We can USE the razor code in javascript in cshtml by using <text> element. < 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 using <text> element. < script type="text/javascript"> @foreach (var item in Model) { < text > //javascript goes here which uses the server values < text > } < script> |
|
| 4. |
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. |
|
| 5. |
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 on the properties of the view model USED. It USES convention that will only display like divs or labels. Edit Templates : These are also model centric but will have editable controls like Textboxes. PARTIAL View : These are view centric. These will differ from templates by the WAY they render the properties (Id's) Eg : CategoryViewModel has Product class property then it will 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. Display Templates : These are model centric. Meaning it depends on the properties of the view model used. It uses convention that will only display like divs or labels. Edit Templates : These are also model centric but will have editable controls like Textboxes. Partial View : These are view centric. These will differ from templates by the way they render the properties (Id's) Eg : CategoryViewModel has Product class property then it will 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. |
|
| 6. |
How We Can Multiple Submit Buttons In Asp.net Mvc? |
|
Answer» Below is the scenario and the solution to SOLVE multiple submit buttons issue. Scenario : @using (Html.BeginForm("MyTestAction","MyTestController") { <INPUT type="submit" value="MySave" /> <input type="submit" value="MyEdit" /> } Solution : PUBLIC ActionResult MyTestAction(STRING submit) //submit will have value EITHER "MySave" or "MyEdit" { // Write code here } Below is the scenario and the solution to solve multiple submit buttons issue. Scenario : @using (Html.BeginForm("MyTestAction","MyTestController") { <input type="submit" value="MySave" /> <input type="submit" value="MyEdit" /> } Solution : Public ActionResult MyTestAction(string submit) //submit will have value either "MySave" or "MyEdit" { // Write code here } |
|
| 7. |
How To Use Jquery Plugins In Asp.net Mvc Validation? |
|
Answer» We can USE dataannotations for validation in ASP.Net 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 ASP.Net 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. |
What Is Representational State Transfer (rest) Mean? |
|
Answer» REST is an architectural style which uses HTTP protocol methods like GET, POST, PUT, and DELETE to access the data. ASP.Net MVC works in this style. In ASP.Net MVC 4 there is a support for Web API which uses to BUILD the service using HTTP verbs. REST is an architectural style which uses HTTP protocol methods like GET, POST, PUT, and DELETE to access the data. ASP.Net MVC works in this style. In ASP.Net MVC 4 there is a support for Web API which uses to build the service using HTTP verbs. |
|
| 9. |
Explain The Tools Used For Unit Testing In Asp.net Mvc? |
|
Answer» Below are the tools USED for UNIT testing :
Below are the tools used for unit testing : |
|
| 10. |
Explain Test Driven Development (tdd) ? |
|
Answer» 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. 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. |
|
| 11. |
Explain The Advantages Of Dependency Injection (di) In Asp.net Mvc? |
|
Answer» Below are the advantages of DI :
Below are the advantages of DI : |
|
| 12. |
What Is Dependency Injection In Asp.net 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. |
|
| 13. |
How We Can Invoke Child Actions In Asp.net 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(); } |
|
| 14. |
What Are Child Actions In Asp.net Mvc? |
|
Answer» 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. 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. |
|
| 15. |
How We Can Register The Area In Asp.net 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(); } |
|
| 16. |
What Is Area In Asp.net 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. |
|
| 17. |
Explain Peek Method In Tempdata In Asp.net 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(); |
|
| 18. |
Explain Keep Method In Tempdata In Asp.net 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"); |
|
| 19. |
Does Tempdata Hold The Data For Other Request In Asp.net 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. |
|
| 20. |
How We Can Handle The Exception At Controller Level In Asp.net Mvc? |
|
Answer» 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) { } 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) { } |
|
| 21. |
What Are Model Binders In Asp.net 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". |
|
| 22. |
How To Make Sure Client Validation Is Enabled In Asp.net 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" /> |
|
| 23. |
In Server How To Check Whether Model Has Error Or Not In Asp.net Mvc? |
|
Answer» This can be DONE in FOLLOWING way : Use class : "HttpRequestBase" and use the method : "HttpMethod" to determine the ACTION request type. This can be done in following way : Use class : "HttpRequestBase" and use the method : "HttpMethod" to determine the action request type. |
|
| 24. |
How Can We Determine Action Invoked From Http Get Or Http Post? |
|
Answer» This can be done in FOLLOWING WAY : Use class : "HttpRequestBase" and use the method : "HttpMethod" to determine the ACTION REQUEST type. This can be done in following way : Use class : "HttpRequestBase" and use the method : "HttpMethod" to determine the action request type. |
|
| 25. |
Mention Some Action Filters Which Are Used Regularly In Asp.net Mvc? |
|
Answer» Below are some ACTION FILTERS used :
Below are some action filters used : |
|
| 26. |
What Is The Need Of Action Filters In Asp.net 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 ASP.Net 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 ASP.Net MVC attributes. |
|
| 27. |
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 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. 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. |
|
| 28. |
Can I Add Asp.net Mvc Testcases 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. |
|
| 29. |
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"/> Below is the sample code snippet to add css to razor views : < link rel="StyleSheet" href="/@Href(~Content/Site.css")" type="text/css"/> |
|
| 30. |
What Is Partialview In Asp.net Mvc? |
|
Answer» 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 :
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 : |
|
| 31. |
What Are The Possible Razor View Extensions? |
|
Answer» 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. 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. |
|
| 32. |
Can We Add Constraints To The Route? If Yes, Explain How We Can Do It? |
|
Answer» YES we can add CONSTRAINTS to ROUTE in following WAYS :
Yes we can add constraints to route in following ways : |
|
| 33. |
Why To Use "{resource}.axd/{*pathinfo}" In Routing In Asp.net 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. |
|
| 34. |
What Are The Components Required To Create A Route In Asp.net Mvc? |
|
Answer» 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. 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. |
|
| 35. |
Can A View Be Shared Across Multiple Controllers? If Yes, How We Can Do That? |
|
Answer» 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. 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. |
|
| 36. |
Explain The Types Of Scaffoldings? |
|
Answer» Below are the types of SCAFFOLDINGS : Below are the types of scaffoldings : |
|
| 37. |
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) functionality in an APPLICATION. The scaffolding will be knowing the NAMING conventions used for models and controllers and views. 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. |
|
| 38. |
What Is Routeconfig.cs In Asp.net Mvc 4? |
|
Answer» "RouteConfig.cs" holds the ROUTING CONFIGURATION for ASP.Net MVC. RouteConfig will be INITIALIZED on Application_Start event registered in Global.asax. "RouteConfig.cs" holds the routing configuration for ASP.Net MVC. RouteConfig will be initialized on Application_Start event registered in Global.asax. |
|
| 39. |
What Is Html.renderpartial? |
|
Answer» 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"); } 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"); } |
|
| 40. |
Why To Use Html.partial In Asp.net 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") |
|
| 41. |
What Are Validation Annotations? |
|
Answer» 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. 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. |
|
| 42. |
How We Can Call A Javascript Function On The Change Of A Dropdown List In Asp.net Mvc? |
|
Answer» 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 ()" })%> 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 ()" })%> |
|
| 43. |
What Is The "helper Page.isajax" Property? |
|
Answer» The Helper Page.IsAjax PROPERTY GETS a value that indicates whether AJAX is being USED during the request of the Web page. The Helper Page.IsAjax property gets a value that indicates whether Ajax is being used during the request of the Web page. |
|
| 44. |
What Are Code Blocks In Views? |
|
Answer» Unlike CODE expressions that are evaluated and SENT to the response, it is the blocks of code that are EXECUTED. This is useful for declaring variables which we MAY be required to be used later. @{ int x = 123; STRING y = "aa"; } Unlike code expressions that are evaluated and sent to the response, it is the blocks of code that are executed. This is useful for declaring variables which we may be required to be used later. @{ int x = 123; string y = "aa"; } |
|
| 45. |
How To Change The Action Name In Asp.net 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. |
|
| 46. |
What Are Non Action Methods In Asp.net Mvc? |
|
Answer» 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 } 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 } |
|
| 47. |
What Are The Sub Types Of Actionresult? |
|
Answer» ACTIONRESULT is USED to represent the ACTION method result. Below are the subtypes of ActionResult :
ActionResult is used to represent the action method result. Below are the subtypes of ActionResult : |
|
| 48. |
Explain The Methods Used To Render The Views In Asp.net Mvc? |
|
Answer» 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. 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. |
|
| 49. |
What Is Viewstart Page In Asp.net 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. |
|
| 50. |
Can You Explain Renderbody And Renderpage In Asp.net 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. |
|