Hello, with my code below I want to populate the dropdown and the grid(with all rows), then if the user makes a selection in the dropdown I want the grid to be refreshed with the filtered rows. The NewPartsRead controller action does return the filtered rows, but the grid does not rebind to the filtered rows returned.
What am I doing wrong?
Index:
@using (Html.BeginForm())
{ <div class="demo-section k-content" style="padding:20px;">
@(Html.Kendo().DropDownList()
.Name("EngMake")
.DataTextField("Text")
.DataValueField("Value")
.BindTo(Model.EngMakeList)
.SelectedIndex(0)
.OptionLabel("Select Engine Manufacturer")
.HtmlAttributes(new { style = "width:300px" })
.Filter(FilterType.Contains)
)
</div>
@(Html.Kendo().Grid(Model.NewParts)
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.EngDescription);
columns.Bound(p => p.PartType);
columns.Bound(p => p.EngYear);
columns.Bound(p => p.EngCylinders);
columns.Bound(p => p.EngBore);
columns.Bound(p => p.PartYears);
columns.Bound(p => p.Partieb);
columns.Bound(p => p.PartNotes);
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.HtmlAttributes(new { style = "height:550px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("Index", "NewPartsRead"))
)
)
}
Controller:
public class NewPartsController : Controller
{
// GET: NewParts
public ActionResult Index()
{
var model = new NewPartsModel();
return View(model);
}
[HttpPost]
public ActionResult NewPartsRead(NewPartsModel newPartsModel)
{
newPartsModel.NewParts = newPartsModel.NewPartsRead(newPartsModel.EngMake);
return Json(newPartsModel.NewParts);
}
}
Model:
protected readonly NewPartsProvider newPartsProvider = new NewPartsProvider();
public string EngMake { get; set; }
public List<DataObjects.NewPart> NewParts { get; set; }
public List<SelectListItem> engMakeList = new List<SelectListItem>();
public IEnumerable<SelectListItem> EngMakeList { get; set; }
public NewPartsModel()
{
foreach (var engMake in newPartsProvider.GetEngMakeList())
engMakeList.Add(new SelectListItem() { Text = engMake, Value = engMake });
EngMakeList = engMakeList;
NewParts = newPartsProvider.GetNewParts();
}
public List<DataObjects.NewPart> NewPartsRead(string engMake)
{
List<DataObjects.NewPart> NewParts = new List<DataObjects.NewPart>();
NewParts = newPartsProvider.GetNewPartsByMake(engMake);
return NewParts;
}