2

Here is my code:

@Url.Content("~/AspNetWebForms/ViewPDF.aspx?id=" + docID.ToString() + "&small=True")

I am dynamically building my Manifest file for Application Caching in MVC4. I know it's on the way out (or appears to be) but I do still need to support older browsers.

The site is in MVC, but we do have a couple ASPX pages because we need to use some legacy controls. So in my manifest file I am trying to create a relative path to the ASPX pages using Url.Content(), which seems to work until I need to add a couple parameters and the "&" is encoded. Without the "&" it seems to work (except that it loads/caches the wrong thing).

And since it's a manifest file, I cannot do a redirect, as any redirect causes the application cache to fail.

Even though it's MVC4, I cannot just start with the "~" because it doesn't get parsed as it would in an image or anchor.

Jesse Sierks
  • 2,258
  • 3
  • 19
  • 30

2 Answers2

4

Just append the query string to the output of Url.Content instead.

@(Url.Content("~/AspNetWebForms/ViewPDF.aspx) + "?id=" + docID.ToString() + "&small=True")

or

@string.Format("{0}?id={1}&small=true", 
    Url.Content("~/AspNetWebForms/ViewPDF.aspx"), docID.ToString())
Paul Abbott
  • 7,065
  • 3
  • 27
  • 45
3

At first I thought it was the Url.Content that was encoding the value, but it's actually the Razor engine doing it. Html.Raw corrected it, though I did have to add an empty line afterwards as the line break was lost, too.

@Html.Raw(Url.Content("~/AspNetWebForms/ViewPDF.aspx?id=" + docID.ToString() + "&small=True"))

Paul Abbott's answer lead me to this conclusion so all thanks to him.

Jesse Sierks
  • 2,258
  • 3
  • 19
  • 30
  • There has to be a better way to do this... Something similar to Url.Action but without having to use a Controller? Any thoughts? – pjdupreez Nov 24 '17 at 07:08
  • @pjdupreez This doesn't use a controller. Just the Razor view. – Jesse Sierks Nov 25 '17 at 19:46
  • 1
    Yes, I know that, but it does not allow you to pass parameters, similar to Url.Action (which does need a controller) so you have to build your query string by hand. – pjdupreez Nov 25 '17 at 19:50