微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在多语言中使用 script type="text/x-template"?

如何解决如何在多语言中使用 script type="text/x-template"?

我将 ASP NET 与 VueJS 一起使用。 ASP NET 渲染视图组件:

<script type="text/x-template" id="form-template">
    @if (string.IsNullOrEmpty(Model.LastName))
    {
        <input asp-for="LastName" class="form-control" maxlength="100" autofocus required />
    }
    else
    {
        <input asp-for="LastName" class="form-control" maxlength="100" required />
    }
</script>

我对 C# 的操作:

    public async Task<ActionResult<ViewComponent>> GetAdditionalFormRegistrationComponentAsync()
    {
            var customerviewmodel = new CustomerAdditionFormviewmodel
            {                    
                LastName = "русские символы"
            };

            return ViewComponent("FormRegistration",customerviewmodel);
        }
    }

视图组件:

    public Task<IViewComponentResult> InvokeAsync(CustomerAdditionFormviewmodel customerviewmodel)
    {
        return Task.Run<IViewComponentResult>(() => View(customerviewmodel));
    }

姓氏写英文输入值OK。但如果姓氏填写俄语,我会得到:

enter image description here

如何解决这个问题?

解决方法

我找到了解决办法。 需要添加 Html.Raw()

<input value=“@Html.Raw(Model.LastName)" class="form-control" maxlength="100" autofocus required />

services.AddWebEncoders(options =>
{
    options.TextEncoderSettings = new TextEncoderSettings();
    options.TextEncoderSettings.AllowRange(UnicodeRanges.All);
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。