【发布时间】: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