【发布时间】:2012-11-02 14:11:12
【问题描述】:
ASP.NET MVC 和编程的新手,我已经搜索了有关此主题的材料,但没有找到针对我的特定问题的具体答案。
我正在进行的项目需要使用 WCF 服务。最初,我从一个有效的 jQuery 自动完成功能开始,但是将代码移动到 WCF 服务中断了一些通信。自动完成功能不再起作用
WCF 服务
public IList<Location> QuickSearchLocation(string term)
{
using (var db = new InspectionEntities())
{
//return all locations except the reserved "Other"
return db.Locations
.Where(r => r.LocationName.Contains(term) && r.LocationId != Constants.OtherId)
.ToList();
}
}
上述代码旨在根据与子表的关系获取用户输入。如果用户输入与子表中的数据不匹配,则用户条目将保存到主数据库中的“其他”列。
控制器
public ActionResult QuickSearchLocation(string term)
{
return Json(_service.QuickSearchLocation(term), JsonRequestBehavior.AllowGet);
}
查看
div class="editor-field">
@Html.TextBoxFor(m=>m.LocationId,new {data_autocomplete = Url.Action("QuickSearchLocation", "Inspection")})
脚本
$(document).ready(function () {
$(":input[data-autocomplete]").each(function () {
$(this).autocomplete({ source: $(this).attr("data-autocomplete")});
});
对我的问题的任何见解都会有所帮助。
【问题讨论】:
-
请不要将“ASP.NET MVC”简单地称为“MVC”。一种是框架,另一种是与语言无关的设计模式。就像你在谈论 IE 时一直使用“互联网”这个名字一样。
-
@tereško 感谢您的课程,问题已被编辑。
标签: jquery asp.net-mvc wcf entity-framework