Controller.JavaScript Method
Creates a JavaScriptResult object.
Namespace: System.Web.Mvc
Assembly: System.Web.Mvc (in System.Web.Mvc.dll)
abstract JavaScript : script:string -> JavaScriptResult override JavaScript : script:string -> JavaScriptResult
Parameters
- script
- Type: System.String
The JavaScript code to run on the client
Return Value
Type: System.Web.Mvc.JavaScriptResultThe JavaScriptResult object that writes the script to the response.
The following example shows how to send jQuery code from the server to the client. The script runs immediately when the client receives it. When the "Test JavaScript" link is selected, the jQuery client script is sent to the browser and the browser displays "JavaScript Passed".
<i><b>JavaScript Passed</b></i> will appear on the next line when you click the <b>Test JavaScript</b> link.<br /> <div id="divResultText"></div> <%= Ajax.ActionLink("Test JavaScript", "TestJavaScript", new AjaxOptions{UpdateTargetId = "divResultText"}) %>
Public Function TestJavaScript() As ActionResult Dim s As String = "$('#divResultText').html('JavaScript Passed');" Return JavaScript(s) End Function
Show: