简体   繁体   中英

JavaScript error when using @Html helper

I saw this answer here but when I used it in my MVC 5 VS 2013 app it throws "Invalid Character error The char is the @

$(document).on("click", "#btExtendDates", function () {
var _date =  @Html.Raw(Json.Encode(Model.PmntDate)); 

});

Adding quotes doesn't work either. It returns a literal string (Which I believe is correct)

var _date =  '@Html.Raw(Json.Encode(Model.PmntDate))'

@Html.Raw/Json.Encode is an HTML helper which can be used only in .cshtml file.

Please move your js code that refers Html helper classes from JavaScript file to cshtml

or atleast the below part

<script>
 var _date = @Html.Raw(Json.Encode(Model.PmntDate))
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM