I recently ran into a puzzling issue with one of my MVC applications. I had a report link with querystring parameters that I was passing from the controller to the view. This link was being consumed by a client side procedure that was opening a new window and passing in the link to display the report.

function ViewReport() {

var reportLink = ‘@ViewData[“ReportLink”]‘;

window.location = reportLink;

}

Example Report Link: http://myreport.mycompany.com/default.aspx?report_id=12345&report_type=2

This worked great in Internet Explorer, but Chrome was replacing the querystring “&” character with “&”, which was breaking the report view.

Report Link in Chrome: http://myreport.mycompany.com/default.aspx?report_id=12345&report_type=2

After doing some research, I was able to resolve the issue using the Html.Raw html helper as follows:

function ViewReport() {

var reportLink = ‘@Html.Raw(@ViewData[“ReportLink”].ToString())‘;

window.location = reportLink;

}

Advertisements