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)

        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?


1 Answers

Hien Nguyen On Best Solutions

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.