开发者

mvc 2 help with xml partials

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>开发者_Python百科;<application><apply toObject='DataValues' styles='myShadow' /></application></styles></chart>");

How can I make the RenderPartial give me back the string without the spaces?


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.

string data = RenderPartialToString("~/..../..../..../Graph.ascx", Model.graph_data);
data.Replace(System.Environment.NewLine, "");
myChart.setDataXML(data);

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 or XmlSerializer or XDocument

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜