简体   繁体   中英

Url.Action is generating non cross browser friendly urls

URl.Action is generating a query string in a way that works on IE8, but not on Chrome when a date is being passed.

Here is our code.

function RunReport( PdfOrExcel) 
{

 var ChartType = "Pdf";
 var argCounter = 0;
 linkUrl = '@Url.Action("ClassAssignmentLoadSummaryReport", "ReportsScheduling", new { PdfOrExcel="[1]", RptDate="[2]" } )';

 var objToSend = new Object();
 value = $('#RptDate').val()

 dataToSend.RptDate =value;

 linkUrl = linkUrl.replace("%5B1%5D", PdfOrExcel);
 linkUrl = linkUrl.replace("%5B2%5D", value );

 w = window.open(linkurl);
 w.focus();

}

(this is a little ugly becuase we unwound several function to get the code above)

It generates a url like this:

/appName/ReportsScheduling/ClassAssignmentLoadSummaryReport?PdfOrExcel=Pdf&RptDate=8/6/2012

If we change it like this it works in Chrome just fine.

/appName/ReportsScheduling/ClassAssignmentLoadSummaryReport?PdfOrExcel=Pdf&RptDate=8/6/2012

I assume we are doing something dumb and it's generating it this way because of that, but I can't figure out what We're doing wrong.

Any help is greatly appreciated.

If it's really getting that messy..

Why not just use..

var href = "/ReportsScheduling/ClassAssignmentLoadSummaryReport?PdfOrExcel=blah&RptDate=blahDate"

It looks like your string is getting encoded. Try wrapping the Url.Action() call with @Html.Raw().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM