0

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!

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.