Books of .Net/Interview Questions Interview Questions and Answers Programs C# Concept OOPS Concept JOBS

Sunday, July 16, 2017

ASP.NET MVC Interview Questions and Answers 2


Question 1) What are HTML Helpers in MVC?
HTML Helpers are like controls in traditional web forms. But HTML helpers are more lightweight compared to web controls as it does not hold viewstate and events.
HTML Helpers returns the HTML string which can be directly rendered to HTML page. 

An HTML helper is a method that is used to render html content in a view. HTML helpers are implemented as extension methods.
For example, to produce the HTML for a textbox with id="firstname" and name="firstname", we can type all the html in the view as shown below
<input type="text" name="firtsname" id="firstname" />

OR

We can use the "TextBox" html helper. 

@Html.TextBox("firstname") 

Question 2) What are AJAX Helpers in 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.

AJAX stands for Asynchronous JavaScript And XML. AJAX enable web applications to retrieve data from the server asynchronously. Web application using AJAX enables partial page updates, ie. only the related section of the page is updated, without reloading the entire page.
main difference between HTML helper and Ajax helper is that the HTML helper calls the controller action method synchronously (i.e entire page refresh) while the AJAX helper calls asynchronously (I.e just refresh the portion of page that display updated info).
For that consider the following situation.
When the  user clicks on the link and you want to redirect user to another different page in that situation you have to use @HTML.ActionLink.
When the user clicks on the link and you don’t want to redirect to different page, but you want them to stay on the same page and display some information or details without Post Back, at that time it’s better to use @AJAX.ActionLink.


Question 3) What are the options can be configured in AJAX helpers?
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 confirm box. 
  • OnBegin – Javascript method name to be given here and this will be called before the AJAX request.
  • OnComplete – Javascript method name to be given here and this will be called at the end of AJAX request.
  • OnSuccess - Javascript method name to be given here and this will be called when AJAX request is successful.
  • OnFailure - Javascript method name to be given here and this will be called when AJAX request is failed.
  • UpdateTargetId – Target element which is populated from the action returning HTML.

Question 4) Explain what is routing? What are the three segments for routing is important?
Routing helps you to decide a URL structure and map the URL with the Controller.
The ASP.NET Routing module is responsible for mapping incoming browser requests to particular MVC controller actions.

Routing is a pattern matching system that monitor the incoming request and figure out what to do with that request. At runtime, Routing engine use the Route table for matching the incoming request's URL pattern against the URL patterns defined in the Route table.
The three segments that are important for routing is

  • ControllerName
  • ActionMethodName
  • Parameter

Question 5) Explain how routing is done in MVC pattern?
There is a group of routes called the RouteCollection, which consists of registered routes in the application.  
The RegisterRoutes method records the routes in this collection.  
A route defines a URL pattern and a handler to use if the request matches the pattern.
The first parameter to the MapRoute method is the name of the route.
The second parameter will be the pattern to which the URL matches.  
The third parameter might be the default values for the placeholders if they are not determined.

You may also like





No comments :

Post a Comment