ASP.NET MVC 2和sparkviewengine渲染单引号到双引号中的HTML5数据 - 属性 [英] ASP.NET MVC 2 and sparkviewengine rendering single quotes to double quotes in html5 data- attribute
问题描述
我在与添加一个JSON值作为一个HTML5页面数据属性的问题。
I'm having a problem with adding a json value as a data-attribute in a html5 page.
我们使用火花视图引擎(1.5版),在我们的asp.net mvc的2.0网站。
We use the spark view engine (v1.5) in our asp.net mvc 2.0 website.
下面的视图code:
<a href='${Url.Action("edit", new { id = vehicle.VehicleId })}' title='Bewerken' class='dialog dialog-edit' data-dialogoptions='{"beforeOpen":"initAlarmZoneForm"}'><span class="silk-icon silk-icon-page-edit"></span></a>
被呈现为:
<a href="/Alarm/AlarmZone/edit/4" title="Bewerken" class="dialog dialog-edit" data-dialogoptions="{"beforeOpen":"initAlarmZoneForm"}"><span class="silk-icon silk-icon-page-edit"></span></a>
注意在数据dialogoptions封闭双引号
一个单引号,需要产生的数据dialogoptions一个有效的JSON字符串属性。
A single quote is required to generate a valid json-string in the data-dialogoptions attribute.
有谁知道是什么原因造成这种行为,我怎么能更改或变通解决呢?
Does anyone know what is causing this behavior and how I can change or work around it?
推荐答案
虽然这更多的是一种解决方法不是一个答案,你并不真的需要得到火花呈现单引号。你可以使用&放大器;#X22;
转义字符其中 JSON.parse
似乎正确解析
Although this is more of a workaround than an answer, you don't really need to get spark to render single quotes. You could use "
escape character which JSON.parse
seems to parse correctly.
看起来像你看到的这种行为由于<一个href=\"http://stackoverflow.com/questions/6329666/stop-sparkview-escaping-html/6340997#6340997\">bug/feature星火视图引擎。
Looks like you're seeing this behavior due to a bug/feature in the Spark view engine.
随着版本的 1.6 ,这种特性被固定。星火现在应该正确preserve单/双引号。
As of version 1.6, this "feature" was "fixed". Spark should now properly preserve single/double quotes.
这篇关于ASP.NET MVC 2和sparkviewengine渲染单引号到双引号中的HTML5数据 - 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!