Calling external Javascript from Action Method

SAR

I am submitting a form and would like that, upon validation, my Action method will return a javascript file that lives in Scripts folder. I have the file's path

<script src="~/Scripts/MyScript.js"></script>

and that is what I have tried (which obviously didn't work)

[HttpPost]
        public ActionResult AddPerson(Person person)
        {            
            if (ModelState.IsValid)
            {

                return Content("<script src='~/Scripts/MyScript.js'></script>");
            }
            return View(person);
        }

How could I do such thing?

Thanks!

Hien Nguyen

You need remove ~ and change to return Content("<script src='/Scripts/MyScript.js'></script>");

I tried to reproduce it can run script in script file.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

calling action method with javascript asp mvc

From Dev

Prevent the user from calling action method directly

From Dev

calling different Action Method from another Controller

From Dev

Why not to use parentheses in front of name of an external function while calling it from addEventListner method in JavaScript

From Dev

Calling Action From Javascript Fails MSCRM

From Dev

Calling Javascript prototype method from another method

From Dev

Calling an async method from Web API action method

From Dev

Calling a method in an angular Component from an external JS file

From Dev

Calling External API with Javascript

From Dev

Calling action from constructor vs a life cycle method

From Dev

Calling controllers method from page with asp-action

From Dev

Calling non-action method from another controller

From Java

Calling Java method from JavaScript using ScriptEngine

From Dev

Calling a C# method from JavaScript

From Dev

MVC Calling ActionResult Method from JavaScript

From Dev

Calling a javascript function from java method in Cordova

From Dev

Calling javascript Service/Method from array object

From Dev

Access calling object from Javascript method

From Dev

Calling a Javascript function from an external js file in the html file

From Dev

Calling Javascript function from external file when loading html page

From Dev

Calling my REST API from my action method instead of calling it directly from my view

From Dev

Interrupting calling data-url-action in Razor View from javascript

From Javascript

Calling ASP.NET MVC Action Methods from JavaScript

From Dev

calling action with string type parameter from JavaScript in MVC

From Dev

Transfering by calling Action method directly?

From Dev

javascript why calling a method from another method in the same class need this?

From Dev

Javascript - Calling a child method from inside a prototype method

From Dev

Javascript OOP - calling a method from a different method of the same class

From Dev

Calling an overloaded C# method that takes an Action<A> or a Action<A,B> from F#

Related Related

  1. 1

    calling action method with javascript asp mvc

  2. 2

    Prevent the user from calling action method directly

  3. 3

    calling different Action Method from another Controller

  4. 4

    Why not to use parentheses in front of name of an external function while calling it from addEventListner method in JavaScript

  5. 5

    Calling Action From Javascript Fails MSCRM

  6. 6

    Calling Javascript prototype method from another method

  7. 7

    Calling an async method from Web API action method

  8. 8

    Calling a method in an angular Component from an external JS file

  9. 9

    Calling External API with Javascript

  10. 10

    Calling action from constructor vs a life cycle method

  11. 11

    Calling controllers method from page with asp-action

  12. 12

    Calling non-action method from another controller

  13. 13

    Calling Java method from JavaScript using ScriptEngine

  14. 14

    Calling a C# method from JavaScript

  15. 15

    MVC Calling ActionResult Method from JavaScript

  16. 16

    Calling a javascript function from java method in Cordova

  17. 17

    Calling javascript Service/Method from array object

  18. 18

    Access calling object from Javascript method

  19. 19

    Calling a Javascript function from an external js file in the html file

  20. 20

    Calling Javascript function from external file when loading html page

  21. 21

    Calling my REST API from my action method instead of calling it directly from my view

  22. 22

    Interrupting calling data-url-action in Razor View from javascript

  23. 23

    Calling ASP.NET MVC Action Methods from JavaScript

  24. 24

    calling action with string type parameter from JavaScript in MVC

  25. 25

    Transfering by calling Action method directly?

  26. 26

    javascript why calling a method from another method in the same class need this?

  27. 27

    Javascript - Calling a child method from inside a prototype method

  28. 28

    Javascript OOP - calling a method from a different method of the same class

  29. 29

    Calling an overloaded C# method that takes an Action<A> or a Action<A,B> from F#

HotTag

Archive