我正在使用Tagify,这基本上是使用jQuery自动完成,
参考:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js"></script>
<script src="../../../Scripts/jquery.tagify.js" type="text/javascript"></script>
<link href="../../../Styles/jqueryTagify.css" rel="stylesheet" type="text/css" />
脚本:
<script>
var myTextArea = $("#txtbox").tagify();
myTextArea.tagify('inputField').autocomplete({
source: function(request, response) {
$.ajax({
type: "POST",
url: "Demo.aspx/GetKeyword",
data: "{'match': '" + request.term + "'}",
dataType: "json",
contentType: "application/json",
success: function(data) {
response($.map(data, function(item) {
return {
label: item,
value: item,
}
}));
}
});
},
position: { of: myTextArea.tagify('containerDiv') },
close: function(event, ui) { myTextArea.tagify('add'); },
});
$('form').submit( function() {
var tagStr = $("#txtbox").tagify('serialize');
alert( "Got tags: " + tagStr );
return false;
});
</script>
HTML是:
<input type="text" id="txtbox" />
<input class="submit" type="submit" value="Get Values" />
因此,当我们点击提交按钮时,我们会从此处获取标签值
var tagStr = $(“#txtbox”)。tagify('serialize');
当我点击getvalues
这样的结果时
我如何在C#中的Code Behind中获取这些值?
答案 0 :(得分:2)
在html中添加隐藏字段:
<input id="hiddenTags" name="tags" type="hidden"/>
并更新提交js:
$('form').submit( function() {
var tagStr = $("#txtbox").tagify('serialize');
alert( "Got tags: " + tagStr );
$('#hiddenTags').val(tagStr);
return false;
});
现在你可以在c#中找到标签:
string tags = Request.Form["tags"];