This is a view logic
@using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "getOurSlider" }))
{
<input type="search" name="term" id="term" placeholder="enter your search" />
@Html.DropDownList("DropSearch", new List<SelectListItem>
{
new SelectListItem { Text = "search by start ", Value = "stSeach", Selected=true},
new SelectListItem { Text = "search by end", Value = "endSearsh"},
new SelectListItem { Text = "search by contains", Value = "conSearch"}
}, "choose search type")
<input type="submit" value="start with search" />
}
This is the code in the controller:
public ActionResult searchWithDropsAj()
{
return View(db.movieTbls.ToList());
}
[HttpPost]
public ActionResult searchWithDropsAj(string term)
{
string searchoptions = Request["DropSearch"];
var productSearch = new List<movieTbl>();
if (searchoptions == "conSearch")
{
productSearch = (from pr in db.movieTbls
where pr.movieName.Contains(term) || pr.movieName == null
select pr).ToList();
}
else if (searchoptions == "stSearch")
{
productSearch = (from pr in db.movieTbls
where pr.movieName.StartsWith(term) || pr.movieName == null
select pr).ToList();
}
else if (searchoptions == "endSearch")
{
productSearch = (from pr in db.movieTbls
where pr.movieName.EndsWith(term) || pr.movieName == null
select pr).ToList();
}
return View(productSearch);
}
I want to use jQuery load when I change the dropdownlist, call the controller action and so on.
I tried many things like this
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var term = $('#term').val();
$('#DropSearch').change(function () {
@*$("#getOurSlider").load('@(Url.Action("searchWithDropsAj", "movieTbls")',
{ term: $("#term").val()});*@
$('#getOurSlider').load('@Url.Action("searchWithDropsAj", "movieTbls")', {term="term" });
});
});
</script>
as I couldn't pass the dropdownlist value to controller action as in action works base on this value and i tried many things but not works for me
To be clear: the problem is passing the parameter to the action searchWithDropsAj he didn't send the value to return the normal view not the search result
searchWithDropsAjmethod?