【问题标题】:bootstrap tagsinput not working in ie引导标签输入在 ie 中不起作用
【发布时间】:2015-07-29 10:04:26
【问题描述】:

我在 asp.net MVC 中创建了一个 webapp,我集成了 bootstrap 3 和 Bootstrap-TagsInput 以对我的数据进行可视化格式化。但是 tagsInput 在 IE 中不起作用。 我在 ie 中测试了 tagsinput 的示例 page 并且工作得很好。 在我的代码剃刀和 jquery 实现下方,用于在我的标签对象中添加 data-role="tagsinput" 属性

<div class="form-group">
    @Html.LabelFor(x => x.Tag)
    @Html.TextBoxFor(x => x.Tag, new { @class = "form-control" })
</div>

JS

$(Document).ready(function () {
    $("#Tag").attr('data-role', 'tagsinput');
});

在IE下的渲染代码:

<div class="form-group">
    <label for="Tag">Tag: </label>
    <input name="Tag" class="form-control" id="Tag" type="text" value="" data-role="tagsinput">
</div>

我在同一个项目中有引导表,这可能是问题吗?

【问题讨论】:

  • 当你拒绝编辑时,请解释这个问题与 MVC 的概念有什么关系。
  • 因为如果我使用 html 标签 Bootstrap-tagsinput 确实有效,但使用 razor 无效,我不明白为什么
  • 为什么不在razor中直接添加data-role='tagsinput'呢? new { @class = "form-control", data-role="tagsinput" }。您可以使用字典来构建 htmlAttributes
  • 如果您在 htmlAtrribute 中遇到破折号登录问题,请使用 AnonymousObjectToHtmlAttributes 助手

标签: c# jquery asp.net-mvc twitter-bootstrap razor


【解决方案1】:

我找到了解决方案。我为 TextBoxFor html 助手创建了一个简单的扩展:

    public static MvcHtmlString TextBoxTagFor<TModel, TProperty>(
         this HtmlHelper<TModel> helper,
         Expression<Func<TModel, TProperty>> expression)
    {
        return helper.TextBoxFor(expression, new { @class = "txt", data_role="tagsinput" });
    }

你可以看到 date-role 变成 data_role 这样剃刀编辑器接受数据角色属性。

【讨论】:

    猜你喜欢
    • 2017-03-15
    • 2014-05-02
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    • 2014-06-13
    • 2021-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多