我是试图使用这个插件 (多鸟(远程)示例),但是后端示例在php中,我的后端是asp.net-mvc。我正在尝试将这个php代码转换成asp.net-mvc。是否可以从asp.net-mvc控制器操作返回数组(而不是使用Json或XML)
<?php
$q = strtolower($_GET["q"]);
if (!$q) return;
$items = array(
"Great <em>Bittern</em>"=>"Botaurus stellaris",
"Little <em>Grebe</em>"=>"Tachybaptus ruficollis",
"Black-necked Grebe"=>"Podiceps nigricollis",
"Common Chiffchaff"=>"Phylloscopus collybita",
"House Finch"=>"Carpodacus mexicanus",
"Green Heron"=>"Butorides virescens",
"Solitary Sandpiper"=>"Tringa solitaria",
"Heuglin's Gull"=>"Larus heuglini"
);
foreach ($items as $key=>$value) {
if (strpos(strtolower($key), $q) !== false) {
echo "$key|$value\n";
}
}
?>发布于 2011-02-19 13:05:24
您可以使用以下内容:
public ActionResult Search(string q)
{
// fetch those from the database
var values = new[] { "value1", "value2", "value3" };
// filter based on the search string the user entered
var result = values.Where(x => x.Contains(q));
// render them to the response
return Content(string.Join("\n", result), "text/plain");
}在你看来:
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.autocomplete.js")" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#items').autocomplete('@Url.Action("search")');
});
</script>
<input type="text" id="items" name="items" />https://stackoverflow.com/questions/5050895
复制相似问题