ASP.NET MVC Interview Questions Part 7
37. What are Sections in ASP.NET MVC?
Answer:
A section allows us to define a region of content within a layout. It accepts one parameter which is the name of the section.
A section in a layout page that can be defined by using the following code.
@section header{
<h1>Header Content</h1>
}
We can render above defined section header on the content page as given below:
@RenderSection("header")
38. What are AJAX helpers?
Answer:
Ajax helper of ASP.NET MVC provides the Ajax functionality to our web application. Ajax helpers are used to create Ajax enable elements like as Ajax enable form and links which perform request asynchronously. AJAX Helpers are extension methods of AJAXHelper class which exist in System.Web.Mvc namespace.
In the example below we create AJAX-enabled link based on action/controller.
@Ajax.ActionLink("Load Products", "GetProducts", new AjaxOptions {UpdateTargetId = "Products-container", HttpMethod = "GET" })
Output:
<a data-ajax="true" data-ajax-method="GET" data-ajax-mode="replace" data-ajax-update="#Products-container" href="/Home/GetProducts">Load Products</a>
39. What is Cross Domain Ajax?
Answer:
By default web browser allows Ajax call only from the origin of the application where our site is hosted. This restriction helps us to prevent cross site scripting (XSS) attacks.
When we want to interact with externally hosted APIs then our web application must support JSONP request or Cross-Origin Resource Sharing.
40. What is the NonAction attributes in ASP.NET MVC?
Answer:
In MVC framework, all the public methods of the controller class are treated as Action method. If our controller class contains a public method and we do not want it to be an action method, then we must mark that method with the NonActionAttribute attribute.
Example:
[NonAction]
public void TestMethod()
{
// Method logic
}