Monday 6 February 2017

MVC interview questions Part 2

1. Ques: What is Routing in ASP.NET MVC? 
Answer:
Routing is process by which incoming  URL request maps to a specific controller action using a Routing Table. Routing has a RouteTable which define URL pattern that maps to the request handler. All the configured routes of an application stored in RouteTable and will be used by Routing engine to determine appropriate handler class or file for an incoming request.

















2. Ques: What are ASP.NET MVC HtmlHelpers?
Answer:
HtmlHelpers is just a method that returns a HTML string and an HTML string to render HTML tags
HtmlHelpers use to render standard HTML tags like HTML <input>, <button> and <img> tags etc.
It generates html control using the model class object in razor view.

The following are lists of HtmlHelper methods
Html.ActionLink
Html.TextBox
Html.TextArea
Html.CheckBox
Html.RadioButton
Html.DropDownList
Html.ListBox
Html.Hidden
Password
Html.Display
Html.Label
Html.Editor


3. Ques:  What are partial views in MVC ? 
Answer:
Partial view is a view, which can render a inside multiple view.
it can render a view inside a another parental view and to create reusable content in the project.
it is just like a user control in Asp.Net Web forms .Partial store in share folder in application.
partial views used for code re-usability.

there are two method through render the partial view :
Partial -   @Html.Partial("_header")
RenderPartial - Html.RenderPartial("_header")


4. Ques: What is Filters in ASP.NET MVC?  How many Types of filters, explain it.
Answer:
To perform specific logic before or after action methods execution is called Filters.

MVC supports following types of filters:

Authorization Filters: It use for security purpose .It is used to implement authorization and authentication for action filters.this filter  Runs first, before any other filters. Authorize filter attribute implements the IAuthorizationFilter interface. The definition of this interface is given below-
public interface IAuthorizationFilter
{
 void OnAuthorization(AuthorizationContext filterContext);
}

Action Filters:
It used to implement the logic that get executed before or after a controller action executes.The IActionFilter interface is used to create an Action Filter which provides two methods OnActionExecuting and OnActionExecuted which will be executed before or after an action is executed respectively.
public interface IActionFilter
{
 void OnActionExecuting(ActionExecutingContext filterContext);
 void OnActionExecuted(ActionExecutedContext filterContext);
}

Result Filters:
It provide extra logic to gets executed before or after a view result gets executed. Result filters are called after the Action filters. The IResultFilter interface is used to create an Result Filter which provides two methods OnResultExecuting and OnResultExecuted which will be executed before or after generating the result for an action respectively.

public interface IResultFilter
{
 void OnResultExecuted(ResultExecutedContext filterContext);
 void OnResultExecuting(ResultExecutingContext filterContext);
}

Exception Filters: Runs only if another action method, or the action result throws an exception. The IExceptionFilter interface is used to create an Exception Filter which provides OnException method which will be executed when exception occurs during the actions execution or filters execution.
public interface IExceptionFilter
{
 void OnException(ExceptionContext filterContext);
}


5. Ques: What is View Engine? What are difference between Razor View Engine and ASPX View Engine?
Answer:
View Engine is responsible for rendering the view into html form to the browser.
There are two type of View Engine Asp.net mvc.
1. Web Form View Engine. (.aspx)
2. Razor View Engine. (.cshtml)

Razor View Engine
  • Razor Engine is an very easy syntax view engine that was introduced with MVC 3.
  • it belong to System.Web.Razor namespace.
  • It has .cshtml (Razor with C#) or .vbhtml (Razor with VB) extension for views.
  • it doesn't support design mode in visual studio.
  • it support TDD (Test Driven Development).
  • Razor View Engine we use Layouts.
  • Razor View Engine we use PartialPage.
  • Razor Engine is a little slow compared to Aspx Engine.
  • Razor Engine prevents Cross-Site Scripting Attacks.
Web Form View Engine

  • It is default view engine for the Asp.net MVC.
  • it belong to System.Web.Mvc.WebFormViewEngine namespace .
  • It has .aspx extension for views.
  • It support design mode in visual studio.
  • It doesn't support TDD (Test Driven Development).
  • ASPX View Engine we use masterPages.
  • ASPX View Engine we use WebUserControls.
  • Aspx Engine is faster compared to Razor Engine.
  • ASPX Engine does not prevent Cross-Site Scripting Attacks.

6. Ques: What are bundling and minification Asp.net MVC ?
Answer:
Bundling:
  • Bundling is technique in which a logical group of files that could be loaded with a single HTTP request.
  • In Bundling multiple file bundle to single file and load at single request.
  • it improves the request load time of the application.
  • Bundle class belong to Microsoft.Web.Optimization namespace.
Ex:
public static void RegisterBundles(BundleCollection bundles) {
     bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
      "~/Content/themes/base/jquery.ui.core.css",
      "~/Content/themes/base/jquery.ui.tabs.css",
      "~/Content/themes/base/jquery.ui.datepicker.css",
      "~/Content/themes/base/jquery.ui.progressbar.css",
      "~/Content/themes/base/jquery.ui.theme.css"));
}

Minification : Minification is process that removing unnecessary characters like white space, newline, tab and comments from the JavaScript and CSS files. Minification reduce the size which cause improved load times of a mvc page.
  • Bundling and Minification are the new features in ASP.NET MVC 4.
  • Bundling and Minification improve the performance of ASP.NET MVC application.


No comments:

Post a Comment

Thank you for comment