Reputation: 310
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!
Upvotes: 0
Views: 49
Reputation: 18975
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.
Upvotes: 1