Razor's auto-escape is messing with me. I'm building a url to feed to jquery's $.load method:
<script>
$("#baz").load('@Url.Action("Method", new { foo=Model.Foo, bar=Model.Bar })');
<script>
The problem is, the url is coming out escaped in the emitted script (& == &)
<script>
$("#baz").load('Method?foo=Foo&bar=Bar');
<script>
So MVC chokes on the request saying that the bar parameter was not provided.
I've tried wrapping the call up in @Html.Raw but that still seems to escape the url. Back on planet aspx, I'd just do <%= instead of <%: but obviously that's no good here :). I also tried putting the parameters in a data object for $.load, but that seems to force a post, not a get (and I want a get here).
This is something I could just fix with routing, but this project's not there yet -- still getting functionality down without messing with routing. On the flip side, I need to be able to eventually route this url, so I don't want to just hardcode the querystring.
Any thoughts?
I just ran a test, and the ampersand was not encoded in my test using Html.Raw, like so:
@Html.Raw(Url.Action("Method", new { foo = Model.Foo, bar = Model.Bar }))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With