代码之家  ›  专栏  ›  技术社区  ›  Chase Florell

MvcHtmlString仍在编码字符

  •  0
  • Chase Florell  · 技术社区  · 15 年前

    我想用 MvcHtmlString.Create 创建一个JavaScript变量。但是输出仍在编码中。

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

    创建以下输出

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

    什么时候真的应该

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

    我怎样才能防止这种情况?

    笔记

    我用的是VB而不是C#

    2 回复  |  直到 13 年前
        1
  •  2
  •   Darin Dimitrov    15 年前

    你的javascript好像坏了。不应该是:

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

    是否尝试将服务器端url帮助程序与客户端值混合使用?

        2
  •  1
  •   Chase Florell    15 年前

    尝试

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