i am watching videos of Scott Allen at pluralsight site, exactly I am talking about this module : https://app.pluralsight.com/player?author=scott-allen&name=mvc4-building-m6-ajax&mode=live&clip=0&course=mvc4-building
So i created exactly the same example as shown at video, but it is not working, I have no idea why and I spent an hours 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" />
Controller action :
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>Above my _Layout.cshtml file which is automatically added to every view page:
<!DOCTYPE html><html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")</head><body><div class="navbar navbar-inverse navbar-fixed-top"><div class="container"><div class="navbar-header"><button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button>
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })</div><div class="navbar-collapse collapse"><ul class="nav navbar-nav"><li>@Html.ActionLink("Home", "Index", "Home")</li><li>@Html.ActionLink("About", "About", "Home")</li><li>@Html.ActionLink("Contact", "Contact", "Home")</li><li>@Html.ActionLink("Dodaj", "Add", "Home")</li><li>@Html.ActionLink("Przegladaj", "Review", "Home")</li><li>@Html.ActionLink("Filtruj", "FilterTest", "Home")</li></ul>
@Html.Partial("_LoginPartial")</div></div></div><div class="container body-content">
@RenderBody()<hr /><footer><p>© @DateTime.Now.Year - My ASP.NET Application</p></footer></div>
@Scripts.Render("~/bundles/otf")
@RenderSection("scripts", required: false)
</body></html>What I know is that this part of Review action :
if(Request.IsAjaxRequest()){returnPartialView("_Review", model);}
Never execute, because ona time I replaced it with return View("Index"), and the site didn't redirected me to the index site when i clicked search
So where is a solution, I have no other idea, I think that I did everything.
help!