【问题标题】:How use script type="text/x-template" with multilanguage?如何在多语言中使用 script type="text/x-template"?
【发布时间】:2021-04-26 01:50:35
【问题描述】:

我将 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));
    }

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

如何解决这个问题?

【问题讨论】:

  • 为什么用 vue/javascript 标记?
  • @evolutionxbox 因为我在这个模板中使用了 vue。我认为我的问题使用 type="text/x-template"
  • 能否更新问题,使代码成为可运行的minimal reproducible example
  • @evolutionxbox 我更新了
  • @Viktor,您也可以使用keyboardmonitor 对其进行标记,因为您使用它们来查看您的网站。 Javascript 和/或 Vue 专家可以帮助您,就像键盘和显示器专家可以帮助您一样多。您的问题归结为您的后端如何为页面提供服务。最多可以用html 标记它,因为它可能与html 编码有关。

标签: html asp.net vue.js keyboard monitor


【解决方案1】:

我找到了解决方案。 需要添加 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);
});

【讨论】:

    猜你喜欢
    • 2011-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-30
    • 1970-01-01
    • 2013-06-13
    • 2011-05-13
    • 2020-10-17
    相关资源
    最近更新 更多