I am watching videos of Scott Allen at pluralsight site.
So i created exactly the same example as shown at video, but it is not working, I have no idea why and spent an hour looking for this, here is my code:
At BoundleConfig.cs file:
bundles.Add(new ScriptBundle("~/bundles/otf").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery-ui-{version}.js",
"~/Scripts/jquery.unobtrusive-ajax.min.js",
"~/Scripts/jquery.validate*"
));
At Web.config file in appSettings section I added:
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
And here we go:
public ActionResult Review(string searchString)
{
var model = _repository.StartDs;
if (!String.IsNullOrEmpty(searchString))
{
model = model.Where(x => x.FirstName.Contains(searchString));
}
if (Request.IsAjaxRequest())
{
return PartialView("_Review", model);
}
return View(model);
}
Review.cshtml file :
@model IEnumerable<nauka.Models.StartData>
@using(Ajax.BeginForm(
new AjaxOptions
{
HttpMethod = "get",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "girlsList"
}))
{
<input type="search" name="searchString"/>
<input type="submit" value="Znajdź" />
}
@Html.Partial("_Review", Model)
_Review.cshtml file:
@model IEnumerable<nauka.Models.StartData>
<div id="girlsList">
<table style="width:100%">
<tr>
<th>ID</th>
<th>Imię</th>
<th>Nazwisko</th>
<th>Wzrost</th>
<th>Rozmiar</th>
<th>Akcje</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.Id</td>
<td>@item.FirstName</td>
<td>@item.LastName</td>
<td>@item.Height</td>
<td>@item.TitsSize</td>
<td>@Html.ActionLink("Usuń", "Delete", new { id = item.Id })</td>
</tr>
}
</table>
</div>
Any ideas? It is simple as can be possible, but when i search items, my scroll position is changing and a page reload, so AJAX is not working, why?