Udostępnij za pośrednictwem


AjaxOptions Class

Represents option settings for running AJAX scripts in an MVC application.

Inheritance Hierarchy

System.Object
  System.Web.Mvc.Ajax.AjaxOptions

Namespace:  System.Web.Mvc.Ajax
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

Syntax

'Declaration
Public Class AjaxOptions
public class AjaxOptions
public ref class AjaxOptions

The AjaxOptions type exposes the following members.

Constructors

  Name Description
Public method AjaxOptions Initializes a new instance of the AjaxOptions class.

Top

Properties

  Name Description
Public property Confirm Gets or sets the message to display in a confirmation window before a request is submitted.
Public property HttpMethod Gets or sets the HTTP request method ("Get" or "Post").
Public property InsertionMode Gets or sets the mode that specifies how to insert the response into the target DOM element.
Public property LoadingElementId Gets or sets the id attribute of an HTML element that is displayed while the Ajax function is loading.
Public property OnBegin Gets or sets the name of the JavaScript function to call immediately before the page is updated.
Public property OnComplete Gets or sets the JavaScript function to call when response data has been instantiated but before the page is updated.
Public property OnFailure Gets or sets the JavaScript function to call if the page update fails.
Public property OnSuccess Gets or sets the JavaScript function to call after the page is successfully updated.
Public property UpdateTargetId Gets or sets the ID of the DOM element to update by using the response from the server.
Public property Url Gets or sets the URL to make the request to.

Top

Methods

  Name Description
Public method Equals Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

This class provides options for methods of the AjaxHelper and AjaxExtensions classes.

Examples

The following example shows how to use the AjaxOptions class to set the ID of the elements that are used to display the status message and to enter text.

<h2><%= Html.Encode(ViewData("Message")) %></h2>
<p>
  Page Rendered: <%= DateTime.Now.ToLongTimeString() %>
</p>
<span id="status">No Status</span>
<br />   
<%=Ajax.ActionLink("Update Status", "GetStatus", New AjaxOptions With {.UpdateTargetId = "status"})%>
<br /><br />
<% Using (Ajax.BeginForm("UpdateForm", New AjaxOptions With {.UpdateTargetId = "textEntered"}))%>
  <%= Html.TextBox("textBox1","Enter text")%>  
  <input type="submit" value="Submit"/>
  <br />
  <span id="textEntered">Nothing Entered</span>
<% End Using%>
<h2><%= Html.Encode(ViewData["Message"]) %></h2>
<p>
    Page Rendered: <%= DateTime.Now.ToLongTimeString() %>
</p>
<span id="status">No Status</span>
<br />   
<%= Ajax.ActionLink("Update Status", "GetStatus", new AjaxOptions{UpdateTargetId="status" }) %>
<br /><br />
<% using(Ajax.BeginForm("UpdateForm", new AjaxOptions{UpdateTargetId="textEntered"})) { %>
  <%= Html.TextBox("textBox1","Enter text")%>  
  <input type="submit" value="Submit"/><br />
  <span id="textEntered">Nothing Entered</span>
<% } %>

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

System.Web.Mvc.Ajax Namespace