Wednesday 1 March 2017

MVC interview questions Part 5

1. Ques: What is Layout in ASP.Net MVC?
Answer:
Layout pages are similar to master pages in traditional web forms.Layout may contains common CSS, jQuery files across the multiple Views and one or more placeholders for which Views provide content. This is used to set the common look across multiple pages.


2. Ques: 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();
}

3. Ques: 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.

4. Ques:  Explain what is the difference between View and Partial View?
Answer:
View
  • It contains the layout page
  • Before any view is rendered, view start page is rendered
  • View might have markup tags like body, html, head, title, meta etc.
  • View is not lightweight as compare to Partial View
Partial View
  • It does not contain the layout page
  • Partial view does not verify for a viewstart.cshtml. We cannot put common code for a partial view within the viewStart.cshtml.page
  • Partial view is designed specially to render within the view and just because of that it does not consist any mark up
  • We can pass a regular view to the RenderPartial method

5. Ques: In Which two case where routing is not implemented or required?
Answer:
Two case where routing is not required are
  • When a physical file is found that matches the URL pattern
  • When routing is disabled for a URL pattern

6. Ques: What is difference between updatemodel and tryupdatemodel ?
Answer:
UpdateModel(): It will throws an exception, if validation fails.
TryUpdateModel(): It will not never throw an exception.if validation fails.


7. Ques: Explain in short the “page lifecycle” of an ASP.NET MVC?
Answer:
Following process are performed by ASP.Net MVC page:
 App initialization
 Routing
 Instantiate and execute controller
 Locate and invoke controller action
 Instantiate and render view


8. Ques: What is Unobtrusive JavaScript in MVC ?
Answer:
Unobtrusive JavaScript is a general term that conveys a general set of guidelines or margins to the term REST.
REST is nothing but the Representational State Transfer.
We can explain Unobtrusive JavaScript as- it is not your particular JavaScript code that you generally use in your markup page.
Example
In spite of using event attributes like

  • 'onbuttonclick'
  • 'onpageload'
  • 'onsubmit'
  • 'onclick'
  • 'mouseover'

Unobtrusive JavaScript, attaches element directly by their ID or class, in the presence of the other attributes.
MVC 3 uses the concept of Unobtrusive JavaScript in these two:

AJAX helpers
(Such as Ajax. ActionLink and Ajax. BeginFrom)
Ajax helpers are most commonly used with JQuery and extensible attributes.

AJAX validations 
Ajax validations are most commonly used to
JSON Binding, JQuery Validations

No comments:

Post a Comment

Thank you for comment