The power of a razor to not run away from a URL

Razor Car Safety is messing with me. I am building a URL to submit to the jquery $ .load method:

<script> $("#baz").load('@Url.Action("Method", new { foo=Model.Foo, bar=Model.Bar })'); <script> 

The problem is that the url comes out escaped in the release of the script (& == &)

 <script> $("#baz").load('Method?foo=Foo&amp;bar=Bar'); <script> 

So MVC is choking on the request, saying that the bar parameter was not provided.

I tried wrapping the call in @ Html.Raw, but it seems to be hiding the url. Let's go back to the aspx planet, I would just do <% = instead of <%: but obviously there’s nothing good here :). I also tried putting the parameters in the data object for $ .load, but this seems like a message, not get (and I want to get here).

This is something I could just fix using routing, but this project does not exist yet - functionality still appears without using routing. On the other hand, I need to be able to ultimately redirect this URL, so I don’t want to just re-encode the request.

Any thoughts?

+7
source share
1 answer

I just checked the test and the ampersand was not encoded in my test using Html.Raw, for example:

 @Html.Raw(Url.Action("Method", new { foo = Model.Foo, bar = Model.Bar })) 
+14
source

All Articles