Razor view engine automatically applying quotes?

前端 未结 3 1276
借酒劲吻你
借酒劲吻你 2021-01-03 19:07

I\'m fairly used to razor now, but I can\'t understand why the following syntax is correct?

  • @Html.ActionLin
  • 3条回答
    •  悲哀的现实
      2021-01-03 19:20

      Just came across this bizarre behavior as well. Logically the following should work.

      @(Model.IsTablet ? "data-options='is_hover: false'" : "")
      

      but is rendered as

      data-options="'is_hover:" false'=""
      

      As Dan states this works correctly

      @(Model.IsTablet ? "data-options=is_hover:false" : "")
      

      rendering as the first example should.

      data-options="is_hover:false"
      

      but if you add a space in the attribute it breaks whatever weird stuff asp.net 4.0 is doing and it thinks your attribute ends at the space.

      And this does not constitute html escaping as what is valid html syntax doesn't work and the whole point of razor is that the razor syntax should work with valid html not break it.

    提交回复
    热议问题