Upgrade from .net 4 to 4.5 breaks Html.Raw call in Javascript

前端 未结 4 2057
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-06 06:53

I have the following code in a c# MVC 3 razor page where I am passing serialized data into a javascript variable for KnockoutJs:

    @{   
        var listDa         


        
4条回答
  •  佛祖请我去吃肉
    2021-01-06 07:40

    I'm using MVC5 and finding the same issue, so I solved it this way, which should work in all versions

    @Html.Raw("var myData = " +  Json.Encode(this.Model.MyData) + ";" )
    

    However, I would use this only in the simplest situations since you lose any intellisense as to VAR type (although it does treat it as a global instance and the compiler doesn't throw a wobbler), so for now I think an initial, empty definition is probably the best way to proceed.

提交回复
热议问题