Search code examples
javascriptjqueryasp.net-mvc-3razorhtml-encode

MvcHtmlString still encoding characters


I'm trying to use MvcHtmlString.Create to create a JavaScript variable. However the output is still being encoded.

var geocode_jsonresult = @MvcHtmlString.Create(Url.Action("GeoLocation", "Generic", New With {.address = "$(this).val()"}));

creates the following output

var geocode_jsonresult = /generic/GeoLocation?address=%24(this).val();

when really it "SHOULD" be

var geocode_jsonresult = /generic/GeoLocation?address=$(this).val();

How can I prevent this?

note

I'm using VB and not C#


Solution

  • Your javascript seems broken. Shouldn't it be:

    var geocode_jsonresult = 
        '@Url.Action("GeoLocation", "Generic")?address=' + 
            encodeUriComponent($(this).val());
    

    Are trying to mix server side url helpers with client-side values?