I am not able to bind search results to the ListView. The ListView always returns 0.
I only wants the bind to happened when the search button is clicked. How to do it?
Code:
@{
ViewBag.Title = "Search";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="col-sm-12">
@using (Html.BeginForm("excSearch", "Search", FormMethod.Post))
{
<div class="col-sm-12" role="form" style="text-align: center;">
<div>
<span style="font-size:40px;">Search</span>
</div>
<div style="padding: 15px; background: rgba(240,240,240,.9)">
<div class="input-group form-group" style="margin-bottom: 0px !important;">
<input type="text" name="search_keyword" placeholder="Enter Keyword..." required="required" class="searchTxtInputs" />
<span class="input-group-addon" style="padding: 0px 8px 0px 8px;"><i class="fa fa-search"></i></span>
</div>
<br />
<div style="text-align: right;">
<div style="padding: 5px; display: inline-block;">
@(Html.Kendo().Button()
.Name("btnSearch")
.Content("Search")
.HtmlAttributes(new { @class = "btn-primary", type = "submit" })
.Events(e => e.Click("execButtonSearch"))
)
</div>
</div>
</div>
</div>
<div class="col-sm-9" style="padding:0px 0px 40px 35px;">
</div>
<div class="articleContainer col-sm-12">
<script type="text/x-kendo-template" id="template">
<div class="row departmentArticleListRow">
#if(MainImage !== null && MainImage !== ""){#
<div class="col-lg-2 departmentArticleListImage Style_1">
#= htmlDecode(MainImage) #
</div>
<div class="col-lg-10 departmentArticleList">
#if(SEO !== null){#
<a href="@Url.RouteUrl("Article", new { departmentName = "SectionName".Replace(' ', '-'), articleName = "articleName", articleID = "articleID" }).Replace("articleName", "#= kendo.toString(replaceString(SEO))#").Replace("articleID", "${Article_ID}").Replace("SectionName", "${SectionName}")"><span class="mediumHeadline">${SEO}</span></a><br /><br />
#}else{#
<a href="@Url.RouteUrl("Article", new { departmentName = "SectionName".Replace(' ', '-'), articleName = "articleName", articleID = "articleID" }).Replace("articleName", "#= kendo.toString(replaceString(Title))#").Replace("articleID", "${Article_ID}").Replace("SectionName", "${SectionName}")"><span class="mediumHeadline">${Title}</span></a><br /><br />
#}#
<span class="departmentArticleListBlurb"> #= htmlDecode(Blurb) #</span><br /><br />
<span class="departmentArticleListIssue">${IssueMonth} </span><span class="departmentArticleListIssue"> ${IssueYear}</span>
</div>
#}else{#
<div class="col-lg-12 departmentArticleList">
#if(SEO !== null){#
<a href="@Url.RouteUrl("Article", new { departmentName = "SectionName".Replace(' ', '-'), articleName = "articleName", articleID = "articleID" }).Replace("articleName", "#= kendo.toString(replaceString(SEO))#").Replace("articleID", "${Article_ID}").Replace("SectionName", "${SectionName}")"><span class="mediumHeadline">${SEO}</span></a><br /><br />
#}else{#
<a href="@Url.RouteUrl("Article", new { departmentName = "SectionName".Replace(' ', '-'), articleName = "articleName", articleID = "articleID" }).Replace("articleName", "#= kendo.toString(replaceString(Title))#").Replace("articleID", "${Article_ID}").Replace("SectionName", "${SectionName}")"><span class="mediumHeadline">${Title}</span></a><br /><br />
#}#
<span class="departmentArticleListBlurb"> #= htmlDecode(Blurb) #</span><br /><br />
<span class="departmentArticleListIssue">${IssueMonth} </span><span class="departmentArticleListIssue"> ${IssueYear}</span>
</div>
#}#
</div>
</script>
<script type="text/javascript">
function replaceString(value) {
if (value)
return value.replace(/\s+/g, "-");
}
</script>
<script type="text/javascript">
function htmlDecode(value) {
if (value) {
if (value.length >= 200) {
var i = 200;
if (value.charAt(i) === ' ') {
value = value.substring(0, i).trim() + "...";
}
else {
while (value.charAt(i) !== ' ') {
value = value.substring(0, i);
i--;
}
value = value.trim() + "...";
}
}
return value.replace(/</g, "<").replace(/>/g, ">").trim();
}
}
</script>
@(Html.Kendo().ListView<DAL_NEW.Article>()
.Name("SearchArticlesList")
.ClientTemplateId("template")
.TagName("div")
.DataSource(datasource =>
{
datasource.Model(model =>
{
model.Id(p => p.Article_ID);
model.Field(p => p.Title);
});
datasource.Read(read => read.Action("excSearch", "Search"));
datasource.PageSize(10);
})
.Pageable()
.HtmlAttributes(new { @class = "departmentListView" })
)
</div>
<script>
function execButtonSearch() {
$("#btnSearch")
.button()
.click(function (event) {
$("#SearchArticlesList").data("kendoListView").dataSource.read();
});
}
</script>
}
</div>
public ActionResult excSearch([DataSourceRequest]DataSourceRequest request, string search_keyword)
{
GetSearchArticles(request, search_keyword);
return View("Search", this);
}
public ActionResult GetSearchArticles([DataSourceRequest]DataSourceRequest request, string search_keyword)
{
List<proc_SearchNewObject> articleList = db.Proc_Search_New(Pub.Pub_ID, "*", search_keyword, null, null, null, null, null).ToList();
return Json(articleList.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
​