【问题标题】:how to assign id to tag , bootstrap tags input, asp.net mvc如何将 id 分配给标签,引导标签输入,asp.net mvc
【发布时间】:2018-07-23 07:32:48
【问题描述】:

我想使用引导标签输入从数据库中添加、删除和显示标签 例如 标签1 标签2 标签3

https://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/

我需要将标签的 id 传递给 action 方法而不是 tagtitle 所以我像这样设置选项的值

<option value="@item.Id">

问题是 tagiputs 显示 1 , 2 , 3 而不是 tag1,tag2,tag3 我的意思是它显示的是 ID 而不是标签标题

所以问题是如何将 id 和 text 分配给标签? 并将标签的 ID 和文本传递给操作?

这是html

        <select multiple data-role="tagsinput" id="testtaginput">
            @{
            foreach (var item in data.TagDataList)
            {
            <option value="@item.Id">@item.TagTitle</option>
            }
            }
        </select>

这是javascript

<script>
$('#testtaginput').on('itemAdded', function (event) {
    debugger;

    var item = event.item;

    $.ajax({
        type: "POST",
        url: '/AddTag?tagtitle=' + item,

    contentType: "application/json; charset=utf-8",
        dataType: "json",
            success: function (response) {

            },
    failure: function (response) {
        alert(response.responseText);
    },
    error: function (response) {
        alert(response.responseText);
    }
    });

});

$('#testtaginput').on('itemRemoved', function(event) {



    var item = event.item;

    $.ajax({
        type: "POST",
        url: '/DeleteTag?tagtitle=' + item,

        contentType: "application/json; charset=utf-8",
        dataType: "json"
    });
});

【问题讨论】:

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


    【解决方案1】:

    你应该设置

     <option value="@item.Id#@item.TagName">
    

    然后 用'#'分割它

    在发送请求之前,你应该创建一个json对象,其中包含Id,TagName等

    {
     "Id" : 1,
     "TagName" : "test"
    }
    

    您应该将对象传递给方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-06
      • 1970-01-01
      • 2015-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      相关资源
      最近更新 更多