MVC4使用bootstrap-tagsinput为Bootstrap标签文本框分配值

时间:2014-10-02 20:35:57

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

使用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"
        });
 });

如何配置以便在文本框中显示?

谢谢,

1 个答案:

答案 0 :(得分:0)

试试吧,

 @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/