mvc 2 帮助处理 xml 部分
好的,为了向 Fusion Charts 提供数据,我需要给它一些 XML。 我已经将其范围缩小到了
myChart.setDataXML("<%Html.RenderPartial("Graph", Model.graph_data); %>");
渲染的范围,
myChart.setDataXML("
<chart caption='Grafico' xAxisName='Factores' yAxisName='Porcentaje' decimals='0' formatNumberScale='0' numberSuffix='%25' yAxisMinValue='0' yAxisMaxValue='100' bgColor='FFFFFF' showBorder='1' bgSWF='/Content/images/LogoGraficas.png' slantLabels='1' labelDisplay='Rotate' baseFontColor='333333'>
<set value='100' label='Pierna' />
<styles>
<definition>
<style name='myShadow' type='Shadow' color='999999' angle='45'/>
</definition>
<application>
<apply toObject='DataValues' styles='myShadow' />
</application>
</styles>
</chart>");
但我需要渲染的是..
myChart.setDataXML("<chart caption='Grafico' xAxisName='Factores' yAxisName='Porcentaje' decimals='0' formatNumberScale='0' numberSuffix='%25' yAxisMinValue='0' yAxisMaxValue='100' bgColor='FFFFFF' showBorder='1' bgSWF='/Content/images/LogoGraficas.png' slantLabels='1' labelDisplay='Rotate' baseFontColor='333333'><set value='100' label='Pierna' /><styles><definition><style name='myShadow' type='Shadow' color='999999' angle='45'/></definition><application><apply toObject='DataValues' styles='myShadow' /></application></styles></chart>");
如何使 RenderPartial 返回不带空格的字符串?
Ok, so in order to provide Data to Fusion Charts I need to give it some XML..
I have narrowed it down to this
myChart.setDataXML("<%Html.RenderPartial("Graph", Model.graph_data); %>");
which renders
myChart.setDataXML("
<chart caption='Grafico' xAxisName='Factores' yAxisName='Porcentaje' decimals='0' formatNumberScale='0' numberSuffix='%25' yAxisMinValue='0' yAxisMaxValue='100' bgColor='FFFFFF' showBorder='1' bgSWF='/Content/images/LogoGraficas.png' slantLabels='1' labelDisplay='Rotate' baseFontColor='333333'>
<set value='100' label='Pierna' />
<styles>
<definition>
<style name='myShadow' type='Shadow' color='999999' angle='45'/>
</definition>
<application>
<apply toObject='DataValues' styles='myShadow' />
</application>
</styles>
</chart>");
But what I need rendered is..
myChart.setDataXML("<chart caption='Grafico' xAxisName='Factores' yAxisName='Porcentaje' decimals='0' formatNumberScale='0' numberSuffix='%25' yAxisMinValue='0' yAxisMaxValue='100' bgColor='FFFFFF' showBorder='1' bgSWF='/Content/images/LogoGraficas.png' slantLabels='1' labelDisplay='Rotate' baseFontColor='333333'><set value='100' label='Pierna' /><styles><definition><style name='myShadow' type='Shadow' color='999999' angle='45'/></definition><application><apply toObject='DataValues' styles='myShadow' /></application></styles></chart>");
How can I make the RenderPartial give me back the string without the spaces?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试 将 PartialView 输出转换为字符串 然后按照你的意愿操纵它。
所以你最终会做的是这样的。
我知道这不是最好的解决方案,但它可能会解决您的问题。
更新:
生成 XML 的更好方法是使用:
XmlWriter
或XmlSerializer
或XDocument
我不是XML Expert,所以我不知道哪个最适合您的情况,但我喜欢
XmlSerializer
的工作方式。请参阅此处的一些示例
You can try to convert the PartialView output to a string and then manipulate it as u wish.
So what you will end up doing is something like this.
I know it's not the best solution but it might fix your problem.
Update :
Better Ways to generate your XML is to use :
XmlWriter
orXmlSerializer
orXDocument
I'm not an XML Expert so i don't know which is best for your case but i like the way the
XmlSerializer
works.See some examples Here