Answer the question
In order to leave comments, you need to log in
I can’t find an error in any way, why is the view not associated with the controller when implementing live search?
Hello. There is such a complexity. I hope you clarify.
1. The goal is to implement a "live" search on the main page of the project. That is came - in process of input - deduces the list of records. In this case, the request may include several parameters: for example, it is entered - Ivan, Lesnaya, 10/10/1980. So that you can search for any matches. To implement this idea, I use jQuery UI, autocomplete.
2. A controller is implemented, to which a query is made to the database.
3. An attempt to implement the search string and interact with the search controller thereof.
I can’t find an error in any way: my view does not display the result of the request and does not communicate with the controller.
@{
ViewBag.Title = "Главная страница";
}
<head>
<link href='@Url.Content("~/Content/themes/base/all.css")' rel="stylesheet" type="text/css" />
</head>
<body>
<p></p>
<p></p>
<p></p>
<p></p>
<input type="text" name="name" data-autocomplete-source='@Url.Action("Search", "Poisk")' />
<input type="submit" value="Поиск" />
<script src='@Url.Content("~/Scripts/jquery-1.12.1.min.js")' type="text/javascript"></script>
<script src='@Url.Content("~/Scripts/jquery-ui-1.12.1.min.js")' type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("[data-autocomplete-source]").each(function () {
var target = $(this);
target.autocomplete({ source: target.attr("data-autocomplete-source") });
});
});
</script>
</body>
@Scripts.Render("~/bundles/jquery")
public class PoiskController : Controller
{
private tsonEntities9 db = new tsonEntities9();
// GET: Poisk
public ActionResult Search(string term)
{
var people = db.people.Select(p => new
{
FamilyPoisk = p.family,
NamePoisk = p.name,
patronymicPoisk = p.patronymic,
date_of_birth_Poisk = p.date_of_birth,
telephonePoisk = p.telephone,
cityPoisk = p.city,
streetPoisk = p.street,
domPoisk = p.dom,
kvartiraPoisk = p.kvartira
});
foreach (var p in people) ;
return Json(JsonRequestBehavior.AllowGet);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question