I have a js file called: myfile.js
It's content looks like:
function fnGetFilterVals(){
var f = '?';
f += '&fltInsertDate=' + $('#fltCreateDate').val();
f += '&fltStatusID=' + $('#fltStatus').val();
@if (ViewBag.GetCompanyID == -1)
{
<text>f += '&fltCompanyIDs=' + $('#fltCompany').val();</text>
}
return f;
}
I create a bundle in BundleConfig.cs:
bundles.Add(new ScriptBundle("~/bundles/myfile").Include("~/static/asset/myfile.js"));
After that, I include it to view "@section Scripts":
@Scripts.Render("~/bundles/myfile")
Since, my file contains @ character, page raises "Uncaught SyntaxError: Unexpected token ILLEGAL" error.
@if (ViewBag.GetCompanyID == -1)
How can I use @ character in a separated js file?
@{ if (..) {...} }.