在将xml插入段落后的参数列表之后丢失)

时间:2015-07-16 14:02:42

标签: javascript asp.net-mvc razor

我正在尝试使用以下代码在对话框窗口中显示一个xml块:

function ShowFaultMessage(message) {
    $("#dialog-confirm").dialog({
        resizable: false,
        height: 400,
        width: 400,
        modal: true,
        position: { my: "left top", at: "left bottom", of: "#btnShowFault" },
        buttons: [{
            text: "Copy",
            id: "btnCopy",
            Click: function () { return true; }
        }]
    });

    document.getElementById("faultParagraph").innerText = message;

    $("#dialog-confirm").dialog("open");

    $("#btnCopy").zclip({
        path: '../Scripts/ZeroClipboard.swf',
        copy: document.getElementById("faultParagraph").innerText,
        afterCopy: function () { }
    });
};

“message”变量包含xml。如果“message”只是一个标准字符串,但是在参数列表之后“缺少”,如果它是一个xml字符串,那么这是有效的。有没有办法让这项工作?我认为它必须与xml中的非转义字符有问题。

这是我的对话框html:

<div id="dialog-confirm" title="Fault Message">
<p id="faultParagraph" class="paragraph-message"></p>

和XML

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
        <Action xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" s:mustUnderstand="1">http://services.com/SendValidationFaultFault</Action>
    </s:Header>
    <s:Body>
        <s:Fault>
            <faultcode>s:Client</faultcode>
            <faultstring xml:lang="en-US">The creator of this fault did not specify a Reason.</faultstring>
            <detail>
                <ValidationFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.microsoft.com/practices/EnterpriseLibrary/2007/01/wcf/validation">
                    <Details xmlns:d6p1="http://schemas.datacontract.org/2004/07/Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF">
                        <d6p1:ValidationDetail>
                            <d6p1:Key>Cost</d6p1:Key>
                            <d6p1:Message>Cost must be greater than .01.</d6p1:Message>
                            <d6p1:Tag>invoice</d6p1:Tag>
                        </d6p1:ValidationDetail>
                        <d6p1:ValidationDetail>
                            <d6p1:Key>Cost</d6p1:Key>
                            <d6p1:Message>Cost must be greater than .01.</d6p1:Message>
                            <d6p1:Tag>invoice</d6p1:Tag>
                        </d6p1:ValidationDetail>
                    </Details>
                </ValidationFault>
            </detail>
        </s:Fault>
    </s:Body>
</s:Envelope>

1 个答案:

答案 0 :(得分:0)

修复是将Json.Encode用于我的参数到函数中。我在构建调用函数的按钮的位置进行了更改。我现在有这个:

 return new HtmlString(string.Format("<input type='submit' id='btnShowFault' onclick='ShowFaultMessage({0})' value='Fault' />", Json.Encode(item.Fault.Message)));

感谢Prusse帮我解决这个问题。