渲染Razor视图时会添加额外的&符号(amp;)

时间:2014-06-15 19:27:23

标签: c# javascript asp.net-mvc asp.net-mvc-4 razor

我有一个Razor视图,它写了一个javascript对象:

var invoices = [
        @foreach (var invoice in Model.PartnerInvoices)
        {
            <text>[{ 'orderid': "@invoice.Id", 'invoiceDate': "@invoice.InvoiceDate.ToString("dd-MM-yyyy")", 'customerName': "@invoice.CustomerName", 'customerCountry': "@invoice.CustomerCountry", 'amount': "@invoice.Amount", 'pdfLink': "@invoice.PdfUrl", 'status': "@(invoice.Status?"Sent":"Not sent")", 'accessId': "@Model.AccessToken", 'downloadPdfLink': "@invoice.DownloadPdfLink" }],</text>
        }
    ];

在控制器中查看时,@invoice.DownloadPdfLink的值如下:

/partner/GetEconomicInvoice?pdfUrl=https://restapi.e-conomic.com/invoices/booked/20245/pdf&token=2IuGl4j2sGKNWw1

请注意,在pdf和token之间,只有一个&符号(&amp;)。

但是,当我在浏览器中查看呈现的源代码时,我得到以下输出。重要的区别是在我的&号之后添加的额外amp;

 var invoices = [
            [{ 'orderid': "20244", 'invoiceDate': "15-06-2014", 'customerName': "LetterAmazer IvS", 'customerCountry': "Denmark", 'amount': "1117,00", 'pdfLink': "https://restapi.e-conomic.com/invoices/booked/20244/pdf", 'status': "Not sent", 'accessId': "D-ctbWsI6dSw1", 'downloadPdfLink': "/partner/GetEconomicInvoice?pdfUrl=https://restapi.e-conomic.com/invoices/booked/20244/pdf&amp;token=D-ctbWsI6dSw1" }],
            [{ 'orderid': "20245", 'invoiceDate': "15-06-2014", 'customerName': "Holtron v. Ib Holdgaard", 'customerCountry': "Denmark", 'amount': "219,00", 'pdfLink': "https://restapi.e-conomic.com/invoices/booked/20245/pdf", 'status': "Not sent", 'accessId': "D-ctbWsI6dSw1", 'downloadPdfLink': "/partner/GetEconomicInvoice?pdfUrl=https://restapi.e-conomic.com/invoices/booked/20245/pdf&amp;token=D-ctbWsI6dSw1" }],
            [{ 'orderid': "20243", 'invoiceDate': "01-06-2014", 'customerName': "Datahouse Ltd.", 'customerCountry': "Data Country", 'amount': "767,00", 'pdfLink': "https://restapi.e-conomic.com/invoices/booked/20243/pdf", 'status': "Sent", 'accessId': "D-ctbWsI6dSw1", 'downloadPdfLink': "/partner/GetEconomicInvoice?pdfUrl=https://restapi.e-conomic.com/invoices/booked/20243/pdf&amp;token=D-ctbWsI6dSw1" }],
    ];

这个额外放大器到底是怎么回事;被添加?以及如何解决?

我试过没有运气的UrlEncode / UrlDecode。仍然添加了amperstand。

0 个答案:

没有答案