我看过许多实现jQuery自动完成功能的示例。大多数原因是:
jquery-1.10.2.js:8706 GET / AddApplication / GetURL?term = s 404(未找到)
我对jQuery经验不足,我认为此错误意味着路径错误?
我正在使用c#和剃须刀页面。
AddApplication.cshtml.cs
类:
[System.Web.Mvc.HttpGet]
public System.Web.Mvc.JsonResult GetURL(string term)
{
System.Web.Mvc.JsonResult result = new
System.Web.Mvc.JsonResult();
var urls = (from c in db.Url
where c.UrlName.StartsWith(term)
select new {c.UrlName});
result.Data = urls;
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
Console.WriteLine("---------"+result);
return result;
}
AddApplication.cshtml
剃须刀前端:
<div>
<input type="text" name="url" id="url" placeholder="Search for a URL"
autocomplete="on">
</div>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/start/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript">
$(function () {
$("#url").autocomplete({
source: "@Url.Action("GetURL","AddApplication")",
minLength: 1,
select: function (event, ui) {
if (ui.item) {
$("#url").val(ui.item.value);
$("form").submit();
}
}
});
});
</script>
据我所知,我已经尝试过在脚本中使用ajax函数,但仍然无法正常工作。
答案 0 :(得分:0)
感谢Rory为我提供了修复程序。
从<Page.Resources>
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<TextBlock local:Translation.TranslationModelID="{TemplateBinding local:Translation.TranslationModelID}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
<Grid>
<Button x:Name="btn" local:Translation.TranslationModelID="1" />
</Grid>
更改来源
到
fn give_me_string(&self) -> &String {
unsafe {
match self.string_ref {
Some(x) => &*(x.as_ptr() as *const _), //without ref
Some(ref x) => x.as_ptr(), // with ref
None => panic!("hello?")
}
}
}
这解决了404 not found错误