【问题标题】:Pass NON Latinic Characters In URL在 URL 中传递非拉丁字符
【发布时间】:2023-03-22 10:13:01
【问题描述】:

我正在尝试将非拉丁字符传递给 mvc 控制器。但值始终为"??????"。这就是我所拥有的。知道如何将这种类型的值传递给控制器​​参数吗?

脚本

            $.ajax({
                url: 'FOV/MCI/Cars?model=Ферари',
                dataType: 'html',
                type: 'POST',
                error: function (xhr) {
                    alert('error');
                },
                success: function (data) {
                    alert('success');
                }
            });

C#:

        [HttpPost]
        public ActionResult Cars(string model)
        {
           //here model is with value ??????
        }

【问题讨论】:

  • 需要在ajax请求中设置contentType contentType: "charset=utf-8"

标签: javascript c# jquery model-view-controller


【解决方案1】:

您需要对查询字符串进行编码,例如使用 encodeURI 对整个 url 进行编码或在查询字符串上使用 encodeURIComponent:

$.ajax({
        url: encodeURI('FOV/MCI/Cars?model=Ферари'),
        dataType: 'html',
        type: 'POST',
        error: function (xhr) {
            alert('error');
        },
        success: function (data) {
            alert('success');
        }
    });

【讨论】:

    猜你喜欢
    • 2010-10-06
    • 2015-05-07
    • 2011-07-01
    • 2012-11-12
    • 2015-06-26
    • 1970-01-01
    • 2015-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多