[英]How do i create cascading textboxes in ASp.net mvc4 using jquery ajax
Guys I stuck to create two cascading textboxes.eg:first-textbox is "tasks" and other is "projects" I want to autocomplete first-textbox and specfic projects loaded in second-textbox which is related to first textbox tasaks...i populate both separately..here is my code for autocomplete tasks and autocomplete projects... 伙计们,我坚持要创建两个级联文本框。例如:第一个文本框是“任务”,其他是“项目”,我想自动完成第一个文本框和特定于第二个文本框中加载的项目,这些项目与第一个文本框tasaks有关... i分别填充两者..这是我的自动完成任务和自动完成项目的代码...
function AutoCompleteTasks() {
$("#txtTasks").autocomplete({
source: function (request, response) {
//debugger;
$.ajax({
url: "/Home/AutoCompleteTasks",
type: "POST",
dataType: "json",
data: { term: request.term },
success: function (data) {
response($.map(data, function (item) {
return { label: item.Name, value: item.Name };
}))
}
})
},
});
}
and for project is 对于项目是
function AutoCompleteProjects() {
$("#txtproject").autocomplete({
source: function (request, response) {
//debugger;
$.ajax({
url: "/Home/AutoCompleteProjects",
type: "POST",
dataType: "json",
data: { term: request.term },
success: function (data) {
response($.map(data, function (item) {
return { label: item.Name, value: item.Name };
}))
}
})
},
});
}
and my Json result code is 我的Json结果代码是
public JsonResult AutoCompleteTasks(string term)
{
var result = (from t in context.Tasks
where t.Name.Contains(term)
select new { t.Name });
return Json(result, JsonRequestBehavior.AllowGet);
}
and for projects is 对于项目是
//load projects on autocomplete
public JsonResult AutoCompleteProjects(string term)
{
var query = (from p in context.Projects
where p.Name.Contains(term)
select new { p.Name }).Distinct();
return Json(query, JsonRequestBehavior.AllowGet);
}
any help will be appreciated.. 任何帮助将不胜感激..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.