Top 50 Asp Dot Net Mvc Interview Questions
Q1. Can I Set The Unlimited Length For "maxjsonlength" Property In Config?
No. We cannot set limitless length for belongings maxJsonLength. Default price is - 102400 and most fee what we are able to set would be : 2147483644.
Q2. What Is The Use .Glimpse In Asp.Net Mvc?
Glimpse is an open supply device for debugging the routes in ASP.Net MVC. It is the customer side debugger. Glimpse must be grew to become on through journeying to nearby url hyperlink - http://localhost:portname//glimpse.Axd This is a famous and useful tool for debugging which tracks the rate details, url information and many others.
Q3. How To Make Sure Client Validation Is Enabled In Asp.Net Mvc?
In Web.Config there are tags referred to as : "ClientValidationEnabled" and "UnobtrusiveJavaScriptEnabled". We can set the customer aspect validation simply through setting these two tags "genuine", then this setting may be implemented at the software degree.
< add key="ClientValidationEnabled" value="true" />
< add key="UnobtrusiveJavaScriptEnabled" value="true" />
Q4. What Are Non Action Methods In Asp.Internet Mvc?
In ASP.Net MVC all public methods were treated as Actions. So if you are growing a technique and in case you do not need to use it as an movement technique then the method needs to be embellished with "NonAction" characteristic as shown beneath :
[NonAction]
public void TestMethod()
// Method logic
Q5. What Are Html Helpers In Asp.Net Mvc?
HTML Helpers are like controls in traditional net forms. But HTML helpers are extra light-weight in comparison to net controls as it does now not maintain viewstate and activities. HTML Helpers returns the HTML string which can be directly rendered to HTML page. Custom HTML Helpers additionally can be created by using overriding "HtmlHelper" magnificence.
Q6. What Is Html.Renderpartial?
Result of the method : "RenderPartial" is without delay written to the HTML reaction. This technique does no longer go back something (void). This technique also does now not rely on action methods. RenderPartial() method calls "Write()" internally and we have to make certain that "RenderPartial" method is enclosed within the bracket. Below is the pattern code snippet : @Html.RenderPartial("TestPartialView");
Q7. What Are The Possible Razor View Extensions?
Below are the two forms of extensions razor view may have :
.Cshtml : In C# programming language this extension will be used.
.Vbhtml - In VB programming language this extension might be used.
Q8. What Are The Differences Between Partial View And Display Template And Edit Templates In Asp.Internet Mvc?
Display Templates : These are model centric. Meaning it relies upon on the houses of the view model used. It uses conference a good way to handiest display like divs or labels.
Edit Templates : These also are version centric however may have editable controls like Textboxes.
Partial View : These are view centric. These will fluctuate from templates with the aid of the manner they render the residences (Id's) Eg : CategoryViewModel has Product elegance property 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 listing.
Q9. Mention Some Action Filters Which Are Used Regularly In Asp.Net Mvc?
Below are a few action filters used :
Authentication
Authorization
HandleError
OutputCache
Q10. How We Can Add The Css In Asp.Net Mvc?
Below is the pattern code snippet to add css to razor views : < link rel="StyleSheet" href="/@Href(~Content/Site.Css")" type="text/css"/>
Q11. What You Mean By Routing In Asp.Internet Mvc?
Routing is a sample matching mechanism of incoming requests to the URL patterns which can be registered in course desk. Class : "UrlRoutingModule" is used for the identical technique.
Q12. What Is The Need Of Action Filters In Asp.Internet Mvc?
Action Filters permit us to execute the code earlier than or after action has been accomplished. This may be executed by using decorating the movement strategies of controls with ASP.Net MVC attributes.
Q13. Does Tempdata Hold The Data For Other Request In Asp.Internet Mvc?
If Tempdata is assigned within the cutting-edge request then it is going to be available for the present day request and the following request and it depends whether or not records in TempData examine or no longer. If information in Tempdata is study then it might not be available for the subsequent requests.
Q14. How We Can Multiple Submit Buttons In Asp.Internet Mvc?
Below is the state of affairs and the answer to resolve more than one post 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 put up) //publish will have price either "MySave" or "MyEdit"
// Write code right here
Q15. Can A View Be Shared Across Multiple Controllers? If Yes, How We Can Do That?
Yes we will share a view across more than one controllers. We can placed the view in the "Shared" folder. When we create a new ASP.Net MVC Project we will see the Layout page may be introduced in the shared folder, that's due to the fact it's miles used by multiple infant pages.
Q16. Explain Tempdata In Asp.Net Mvc?
TempData is once more a key, cost pair as ViewData. This is derived from "TempDataDictionary" magnificence. TempData is used when the records is to be used in two consecutive requests, this could be among the movements or between the controllers. This calls for typecasting in view.
Q17. What Is Partialview In Asp.Internet Mvc?
PartialView is much like UserControls in traditional web bureaucracy. For re-usability cause partial views are used. Since it is been shared with a couple of perspectives those are kept in shared folder.
Partial Views may be rendered in following methods :
Html.Partial()
Html.RenderPartial()
Q18. Explain Bundle.Config In Asp.Internet Mvc4?
"BundleConfig.Cs" in ASP.Net MVC4 is used to register the bundles by means of the bundling and minification machine. Many bundles are delivered by way of default together with jQuery libraries like - jquery.Validate, Modernizr, and default CSS references.
Q19. What Are Validation Annotations?
Data annotations are attributes which can be observed in the "System.ComponentModel.DataAnnotations" namespace. These attributes might be used for server-aspect validation and consumer-aspect validation is likewise supported. Four attributes - Required, String Length, Regular Expression and Range are used to cover the commonplace validation scenarios.
Q20. Tell Us Something About Model, View And Controllers In Asp.Net Mvc?
Model : It is largely a business entity which is used to represent the application facts.
Controller : The Request that's despatched with the aid of the person constantly scatters thru controller and it is obligation is to redirect to the unique view using View () technique.
View : it's the presentation layer of ASP.Net MVC.
Q21. Breifly Explain Us What Is Asp.Net Mvc?
ASP.Net MVC is a sample that's used to split the application's implementation good judgment into 3 components i.E. Fashions, perspectives, and controllers.
Q22. Can We Add Constraints To The Route? If Yes, Explain How We Can Do It?
Yes we are able to upload constraints to path in following approaches :
Using Regular Expressions
Using item which implements interface - IRouteConstraint.
Q23. What Is The Meaning Of Unobtrusive Javascript? Explain Us By Any Practical Example?
This is a widespread time period that conveys a trendy philosophy, much like the term REST (Representational State Trfer). Unobtrusive JavaScript does not inter mix JavaScript code on your web page markup. Eg : Instead of using activities like onclick and onsubmit, the unobtrusive JavaScript attaches to elements with the aid of their ID or magnificence primarily based on the HTML5 information- attributes.
Q24. Explain Test Driven Development (tdd) ?
TDD is a technique which says, write your exams first earlier than you write your code. In TDD, tests pressure your utility design and development cycles. You do not do the test-in of your code into source manipulate till all your unit checks pass.
Q25. What Is Routeconfig.Cs In Asp.Internet Mvc four?
"RouteConfig.Cs" holds the routing configuration for ASP.Net MVC. RouteConfig could be initialized on Application_Start event registered in Global.Asax.
Q26. What Is Viewdata?
Viewdata carries the key, value pairs as dictionary and that is derived from class : "ViewDataDictionary". In motion method we're setting the fee for viewdata and in view the fee may be fetched through typecasting.
Q27. Can You Explain Renderbody And Renderpage In Asp.Internet Mvc?
RenderBody is like ContentPlaceHolder in internet bureaucracy. This will exist in layout web page and it'll render the kid pages/perspectives. Layout page may have only one RenderBody() approach. RenderPage also exists in Layout web page and a couple of RenderPage() can be there in Layout page.
Q28. How We Can Call A Javascript Function On The Change Of A Dropdown List In Asp.Net Mvc?
Create a JavaScript approach:
feature DrpIndexChanged() Invoke the approach:
< %:Html.DropDownListFor(x => x.SelectedProduct, new SelectList(Model.Customers, "Value", "Text"), "Please Select a Customer", new identity = "ddlCustomers", onchange=" DrpIndexChanged ()" )%>
Q29. Explain The Advantages Of Dependency Injection (di) In Asp.Internet Mvc?
Below are the blessings of DI :
Reduces class coupling
Increases code reusing
Improves code maintainability
Improves utility testing
Q30. How Can We Determine Action Invoked From Http Get Or Http Post?
This can be finished in following manner : Use class : "HttpRequestBase" and use the technique : "HttpMethod" to decide the movement request kind.
Q31. What Is The Use Of View Model In Asp.Internet Mvc?
View Model is a undeniable magnificence with houses, that's used to bind it to strongly typed view. View Model may have the validation rules described for its houses the use of facts annotations.
Q32. What Are Child Actions In Asp.Internet Mvc?
To create reusable widgets child moves are used and this may be embedded into the figure perspectives. In ASP.Net MVC Partial perspectives are used to have reusability within the software. Child action mainly returns the partial views.
Q33. Which Are The Important Namespaces Used In Asp.Internet Mvc?
Below are the essential namespaces utilized 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
Q34. What Is The Difference Between Viewbag And Viewdata In Asp.Internet Mvc?
ViewBag is a wrapper around ViewData, which allows to create dynamic properties. Advantage of viewbag over viewdata might be : In ViewBag no need to typecast the gadgets as in ViewData. ViewBag will take benefit of dynamic keyword which is introduced in model four.@But earlier than using ViewBag we should keep in mind that ViewBag is slower than ViewData.
Q35. How We Can Register The Area In Asp.Net Mvc?
When we've created an area make certain this will be registered in "Application_Start" event in Global.Asax.
Below is the code snippet in which area registration is executed :
included void Application_Start()
AreaRegistration.RegisterAllAreas();
Q36. What Is Razor View Engine?
Razor is the first major replace to render HTML in ASP.Net MVC @Razor become designed especially for view engine syntax. Main awareness of this will be to simplify and code-centered templating for HTML technology.
Below is the pattern of the use of Razor:
@version ASP.Net MVCMusicStore.Models.Customer
@ViewBag.Title = "Get Customers";
< div class="cust">
@Model.CustomerName
Q37. Why To Use "useful resource.Axd/*pathinfo" In Routing In Asp.Internet Mvc?
Using this default course - useful resource.Axd/*pathInfo, we will save you the requests for the net assets files like - WebResource.Axd or ScriptResource.Axd from passing to a controller.
Q38. 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) capability in an software. The scaffolding might be understanding the naming conventions used for models and controllers and views.
Q39. Explain The Types Of Scaffoldings?
Below are the varieties of scaffoldings :
Empty
Create
Delete
Details
Edit
List
Q40. How To Use Jquery Plugins In Asp.Net Mvc Validation?
We can use dataannotations for validation in ASP.Net MVC. If we want to apply validation during runtime the usage of 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("upload",
required: proper,
minlength: 2,
messages:
required: "Please input call",
minlength: "Minimum period is two"
);
Q41. In Server How To Check Whether Model Has Error Or Not In Asp.Net Mvc?
This can be done in following manner : Use magnificence : "HttpRequestBase" and use the technique : "HttpMethod" to decide the movement request kind.
Q42. How We Can Handle The Exception At Controller Level In Asp.Internet Mvc?
Exception Handling is made easy in ASP.Net MVC and it can be executed by means of simply overriding "OnException" and set the result belongings of the filtercontext object (as shown below) to the view element, that's to be lower back in case of exception.
Included overrides void OnException(ExceptionContext filterContext)
Q43. What Is Dependency Injection In Asp.Internet Mvc?
It is a design sample and is used for developing loosely couple code. This is significantly used inside the software initiatives. This will reduce the coding in case of adjustments on undertaking layout so that is vastly used.
Q44. How Can I Return String Result From Action In Asp.Internet Mvc?
Below is the code snippet to return string from action method :
public ActionResult TestAction()
return Content("Hello Test !!");
Q45. What Is Separation Of Concerns In Asp.Net Asp.Net Mvc?
It is the method of breaking this system into various awesome functions which overlaps in functionality as low as viable. ASP.Net MVC pattern issues on separating the content from presentation and facts-processing from content material.
Q46. Can I Use Razor Code In Javascript In Asp.Internet Mvc?
Yes. We can use the razor code in javascript in cshtml by way of using <text> detail.
< script type="text/javascript">
@foreach (var item in Model)
< text >
//javascript goes here which makes use of the server values
< text >
< script>
Q47. Why To Use Html.Partial In Asp.Internet Mvc?
This technique is used to render the desired partial view as an HTML string. This technique does not rely on any motion techniques.
We can use this like under :
@Html.Partial("TestPartialView")
Q48. What Is Representational State Trfer (rest) Mean?
REST is an architectural style which makes use of HTTP protocol techniques like GET, POST, PUT, and DELETE to get entry to the records. ASP.Net MVC works on this style. In ASP.Net MVC 4 there is a guide for Web API which makes use of to construct the provider the usage of HTTP verbs.
Q49. What Is Layout In Asp.Net Mvc?
Layout pages are just like master pages in traditional net bureaucracy. This is used to set the common appearance across a couple of pages. In every baby page we can locate : /p>
@
Layout = "~/Views/Shared/TestLayout1.Cshtml";
This indicates child page makes use of TestLayout web page as it's master web page.
Q50. What Are The Components Required To Create A Route In Asp.Internet Mvc?
Name - This is the name of the course.
URL Pattern : Placeholders may be given to healthy the request URL pattern.
Defaults :When loading the application which controller, movement to be loaded at the side of the parameter.

