Jero Lopez
Jero Lopez

Reputation: 398

calling JavaScriptResult action methods from jQuery

I want to execute Java Script generated from an MVC action method, I read that JavaScriptResult type can be used for that porpouse, but my question is if it can be called from jQuery.

Controller:

public JavaScriptResult myActionMethods() {

     return JavaScript("alert('" + DateTime.Now.ToString() + "');");
}

JavaScript file:

function CallActionMethodScript() {
     //I want to execute the resulting script using jQuery...
 }

Any idea?

Upvotes: 0

Views: 487

Answers (1)

SLaks
SLaks

Reputation: 887837

Call $.getScript(someUrl) to add a <script> tag that calls your action.

Upvotes: 2

Related Questions