在URL中传递非拉丁字符

Pass NON Latinic Characters In URL

本文关键字:丁字符 字符 URL      更新时间:2023-09-26

我试图通过非拉丁字符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 ??????
        }

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

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