Export (0) Print
Expand All

AjaxExtensions Class

.NET Framework 4

Represents support for ASP.NET AJAX within an ASP.NET MVC application.

System.Object
  System.Web.Mvc.Ajax.AjaxExtensions

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

public static class AjaxExtensions

  NameDescription
Public methodStatic memberActionLink(AjaxHelper, String, String, AjaxOptions)Returns an anchor element that contains the URL to the specified action method; when the action link is clicked, the action method is invoked asynchronously by using JavaScript.
Public methodStatic memberActionLink(AjaxHelper, String, String, Object, AjaxOptions)Returns an anchor element that contains the URL to the specified action method; when the action link is clicked, the action method is invoked asynchronously by using JavaScript.
Public methodStatic memberActionLink(AjaxHelper, String, String, String, AjaxOptions)Returns an anchor element that contains the URL to the specified action method; when the action link is clicked, the action method is invoked asynchronously by using JavaScript.
Public methodStatic memberActionLink(AjaxHelper, String, String, RouteValueDictionary, AjaxOptions)Returns an anchor element that contains the URL to the specified action method; when the action link is clicked, the action method is invoked asynchronously by using JavaScript.
Public methodStatic memberActionLink(AjaxHelper, String, String, Object, AjaxOptions, Object)Returns an anchor element that contains the URL to the specified action method; when the action link is clicked, the action method is invoked asynchronously by using JavaScript.
Public methodStatic memberActionLink(AjaxHelper, String, String, String, Object, AjaxOptions)Returns an anchor element that contains the URL to the specified action method; when the action link is clicked, the action method is invoked asynchronously by using JavaScript.
Public methodStatic memberActionLink(AjaxHelper, String, String, String, RouteValueDictionary, AjaxOptions)Returns an anchor element that contains the URL to the specified action method; when the action link is clicked, the action method is invoked asynchronously by using JavaScript.
Public methodStatic memberActionLink(AjaxHelper, String, String, RouteValueDictionary, AjaxOptions, IDictionary<String, Object>)Returns an anchor element that contains the URL to the specified action method; when the action link is clicked, the action method is invoked asynchronously by using JavaScript.
Public methodStatic memberActionLink(AjaxHelper, String, String, String, Object, AjaxOptions, Object)Returns an anchor element that contains the URL to the specified action method; when the action link is clicked, the action method is invoked asynchronously by using JavaScript.
Public methodStatic memberActionLink(AjaxHelper, String, String, String, RouteValueDictionary, AjaxOptions, IDictionary<String, Object>)Returns an anchor element that contains the URL to the specified action method; when the action link is clicked, the action method is invoked asynchronously by using JavaScript.
Public methodStatic memberActionLink(AjaxHelper, String, String, String, String, String, String, Object, AjaxOptions, Object)Returns an anchor element that contains the URL to the specified action method; when the action link is clicked, the action method is invoked asynchronously by using JavaScript.
Public methodStatic memberActionLink(AjaxHelper, String, String, String, String, String, String, RouteValueDictionary, AjaxOptions, IDictionary<String, Object>)Returns an anchor element that contains the URL to the specified action method; when the action link is clicked, the action method is invoked asynchronously by using JavaScript.
Public methodStatic memberBeginForm(AjaxHelper, AjaxOptions)Writes an opening <form> tag to the response.
Public methodStatic memberBeginForm(AjaxHelper, String, AjaxOptions)Writes an opening <form> tag to the response.
Public methodStatic memberBeginForm(AjaxHelper, String, Object, AjaxOptions)Writes an opening <form> tag to the response.
Public methodStatic memberBeginForm(AjaxHelper, String, String, AjaxOptions)Writes an opening <form> tag to the response.
Public methodStatic memberBeginForm(AjaxHelper, String, RouteValueDictionary, AjaxOptions)Writes an opening <form> tag to the response.
Public methodStatic memberBeginForm(AjaxHelper, String, Object, AjaxOptions, Object)Writes an opening <form> tag to the response.
Public methodStatic memberBeginForm(AjaxHelper, String, String, Object, AjaxOptions)Writes an opening <form> tag to the response.
Public methodStatic memberBeginForm(AjaxHelper, String, String, RouteValueDictionary, AjaxOptions)Writes an opening <form> tag to the response.
Public methodStatic memberBeginForm(AjaxHelper, String, RouteValueDictionary, AjaxOptions, IDictionary<String, Object>)Writes an opening <form> tag to the response.
Public methodStatic memberBeginForm(AjaxHelper, String, String, Object, AjaxOptions, Object)Writes an opening <form> tag to the response.
Public methodStatic memberBeginForm(AjaxHelper, String, String, RouteValueDictionary, AjaxOptions, IDictionary<String, Object>)Writes an opening <form> tag to the response.
Public methodStatic memberBeginRouteForm(AjaxHelper, String, AjaxOptions)Writes an opening <form> tag to the response using the specified routing information.
Public methodStatic memberBeginRouteForm(AjaxHelper, String, Object, AjaxOptions)Writes an opening <form> tag to the response using the specified routing information.
Public methodStatic memberBeginRouteForm(AjaxHelper, String, RouteValueDictionary, AjaxOptions)Writes an opening <form> tag to the response using the specified routing information.
Public methodStatic memberBeginRouteForm(AjaxHelper, String, Object, AjaxOptions, Object)Writes an opening <form> tag to the response using the specified routing information.
Public methodStatic memberBeginRouteForm(AjaxHelper, String, RouteValueDictionary, AjaxOptions, IDictionary<String, Object>)Writes an opening <form> tag to the response using the specified routing information.
Public methodStatic memberGlobalizationScript(AjaxHelper)Returns an HTML script element that contains a reference to a globalization script that defines the culture information.
Public methodStatic memberGlobalizationScript(AjaxHelper, CultureInfo)Returns an HTML script element that contains a reference to a globalization script that defines the specified culture information.
Public methodStatic memberRouteLink(AjaxHelper, String, Object, AjaxOptions)Returns an anchor element that contains the virtual path for the specified route values; when the link is clicked, a request is made to the virtual path asynchronously by using JavaScript.
Public methodStatic memberRouteLink(AjaxHelper, String, String, AjaxOptions)Returns an anchor element that contains the virtual path for the specified route values; when the link is clicked, a request is made to the virtual path asynchronously by using JavaScript.
Public methodStatic memberRouteLink(AjaxHelper, String, RouteValueDictionary, AjaxOptions)Returns an anchor element that contains the virtual path for the specified route values; when the link is clicked, a request is made to the virtual path asynchronously by using JavaScript.
Public methodStatic memberRouteLink(AjaxHelper, String, Object, AjaxOptions, Object)Returns an anchor element that contains the virtual path for the specified route values; when the link is clicked, a request is made to the virtual path asynchronously by using JavaScript.
Public methodStatic memberRouteLink(AjaxHelper, String, String, Object, AjaxOptions)Returns an anchor element that contains the virtual path for the specified route values; when the link is clicked, a request is made to the virtual path asynchronously by using JavaScript.
Public methodStatic memberRouteLink(AjaxHelper, String, String, AjaxOptions, IDictionary<String, Object>)Returns an anchor element that contains the virtual path for the specified route values; when the link is clicked, a request is made to the virtual path asynchronously by using JavaScript.
Public methodStatic memberRouteLink(AjaxHelper, String, String, AjaxOptions, Object)Returns an anchor element that contains the virtual path for the specified route values; when the link is clicked, a request is made to the virtual path asynchronously by using JavaScript.
Public methodStatic memberRouteLink(AjaxHelper, String, String, RouteValueDictionary, AjaxOptions)Returns an anchor element that contains the virtual path for the specified route values; when the link is clicked, a request is made to the virtual path asynchronously by using JavaScript.
Public methodStatic memberRouteLink(AjaxHelper, String, RouteValueDictionary, AjaxOptions, IDictionary<String, Object>)Returns an anchor element that contains the virtual path for the specified route values; when the link is clicked, a request is made to the virtual path asynchronously by using JavaScript.
Public methodStatic memberRouteLink(AjaxHelper, String, String, Object, AjaxOptions, Object)Returns an anchor element that contains the virtual path for the specified route values; when the link is clicked, a request is made to the virtual path asynchronously by using JavaScript.
Public methodStatic memberRouteLink(AjaxHelper, String, String, RouteValueDictionary, AjaxOptions, IDictionary<String, Object>)Returns an anchor element that contains the virtual path for the specified route values; when the link is clicked, a request is made to the virtual path asynchronously by using JavaScript.
Public methodStatic memberRouteLink(AjaxHelper, String, String, String, String, String, RouteValueDictionary, AjaxOptions, IDictionary<String, Object>)Returns an anchor element that contains the virtual path for the specified route values; when the link is clicked, a request is made to the virtual path asynchronously by using JavaScript.
Top

The AjaxExtensions class contains methods that extend the AjaxHelper class. Each extension method renders an HTML element. The ActionLink method renders an anchor (a) element that links to an action method. The RouteLink method renders an anchor (a) element that links to a URL, which can resolve to an action method, a file, a folder, or some other resource. This class also contains BeginForm and BeginRouteForm methods that help you create HTML forms that are supported by AJAX functions.

The following example shows a view that calls the ActionLink method, the BeginRouteForm method, the BeginForm method, and the BeginRouteForm method. The ActionLink method links to an action method that updates a status message that contains a time stamp. The RouteLink method links to the same action method and updates a second status message. The BeginForm method creates a form that contains a text box where the user can enter a message that is displayed with the time the message was entered. The BeginRouteForm method creates a second form that also contains a text box for entering a message.


<h2><%= Html.Encode(ViewData["Message"]) %></h2>
<p>
Page Rendered: <%= DateTime.Now.ToLongTimeString() %>
</p>
<span id="status">No Status</span>
<p>
<%= Ajax.ActionLink("Update Status", "GetStatus", 
    new AjaxOptions{ UpdateTargetId = "status" }) %>
</p>
<span id="routeStatus">No Route Status</span>
<p>
<%= Ajax.RouteLink("Update Status with Route", 
    new RouteValueDictionary{{"controller", "Home"}, {"action", "GetStatus"}},
    new AjaxOptions { UpdateTargetId = "routeStatus" })%>
</p>
<p>
<% using(Ajax.BeginForm("UpdateForm", 
   new AjaxOptions{UpdateTargetId="textEntered1"})) { %>
     <%= Html.TextBox("textBox1","Enter text")%>  
     <input type="submit" value="Submit"/><br />
     <span id="textEntered1">Nothing Entered</span>
<% } %>
</p>
<p>
<% using(Ajax.BeginRouteForm( null,
   new RouteValueDictionary {{"controller", "Home"}, {"action", "UpdateRouteForm"}}, 
   new AjaxOptions{UpdateTargetId="textEntered2"})) { %>
     <%= Html.TextBox("textBox2","Enter text")%>  
     <input type="submit" value="Submit with Route"/><br />
     <span id="textEntered2">Nothing Entered</span>
<% } %>
</p>


To support AJAX in the view, the following script references must be added to the master view.

<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>

The following example shows the HomeController class that supports the view that is listed in the previous example. The GetStatus method is called by both the ActionLink and RouteLink methods and returns a status string. The UpdateForm method is called when the form created by BeginForm is submitted. This method returns a message to be displayed. The UpdateRouteForm method is called when the form that is created by BeginRouteForm is submitted. This method also returns a message to display.


<HandleError()> _
Public Class HomeController
    Inherits System.Web.Mvc.Controller

    Function Index() As ActionResult
        ViewData("Message") = "ASP.NET MVC and AJAX"

        Return View()
    End Function

    Function About() As ActionResult
        Return View()
    End Function

    Public Function GetStatus() As String
        Return "Status OK at " + DateTime.Now.ToLongTimeString()
    End Function

    Public Function UpdateForm(ByVal textBox1 As String) As String
        If textBox1 <> "Enter text" Then
            Return "You entered: """ + textBox1.ToString() + """ at " + DateTime.Now.ToLongTimeString()
        End If

        Return [String].Empty
    End Function

    Public Function UpdateRouteForm(ByVal textBox2 As String) As String
        If textBox2 <> "Enter text" Then
            Return "You entered: """ + textBox2.ToString() + """ at " + DateTime.Now.ToLongTimeString()
        End If

        Return [String].Empty
    End Function
End Class


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

Community Additions

ADD
Show:
© 2014 Microsoft