【问题标题】:MVC4 Assigning Value to Bootstrap Tag Text Box using bootstrap-tagsinputMVC4 使用 bootstrap-tagsinput 为引导标记文本框赋值
【发布时间】:2014-10-03 06:02:50
【问题描述】:

使用 bootstrap-tagsinputs 插件,我想在加载视图时为文本框分配值。

传递给视图的值格式是“a,b,c”

这行得通

@Html.TextBoxFor(model => model.mylist, new {@class = "form-control"})

但是当我添加 data_role = "tagsinput" 时它不起作用

@Html.TextBoxFor(model => model.mylist, new {@class = "form-control", data_role = "tagsinput" })

也尝试过,但没有成功

$(function () {

    var elt = $("#mylisttags-input");
    elt.tagsinput({
        itemText: "@Model.mylist"
        });
 });

如何配置使其显示在文本框中?

谢谢,

【问题讨论】:

    标签: asp.net-mvc-4 bootstrap-tags-input


    【解决方案1】:

    试试看,

     @Html.TextBoxFor(model => model.mylist, new {@class = "form-control", data_role = "tagsinput" })
    
     $("#mylisttags-input").tagsinput('items'); // to show just pass the items key
    

    http://jsfiddle.net/754wob2q/

    【讨论】:

    • 在您的示例中,您提供了默认设置值。我正在尝试将值从控制器传递到模型参数中的视图并将其分配给文本框。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-21
    • 1970-01-01
    相关资源
    最近更新 更多