Hi everybody,
First of all, I'd like to say that I'm completely new to ASP.Net MVC and Kendo UI, and that I'm coming from the WPF world. That might give you some clues about the difficulties I'm facing here ;)
The scenario is quite basic, but I'm not able to achieve what I need to.
Let's image I have a form, that contains 4 search criteria.
- Start Date
- End Date
- Number
- String (city name)
From those 4 fields, I'm trying to feed a Grid in the same page (in AJAX), with data that is coming from an WCF webservice.
I've tried several ways to achieve this but everytime I'm facing a dead-en.
Here's a sample of my code.
The form:
The Grid :
JS Update method
Now the controller:
Obviously, when entering the Search Action, my iModel isn't updated with the latest data from the form. That's the main painpoint I have since the process I'm doing with the WCF service call doesn't have the correct Search criteria.
Hope I was clear enough !
Let me know if you're missing parts to give me a hand !
Thanks a lot !
Julien.
First of all, I'd like to say that I'm completely new to ASP.Net MVC and Kendo UI, and that I'm coming from the WPF world. That might give you some clues about the difficulties I'm facing here ;)
The scenario is quite basic, but I'm not able to achieve what I need to.
Let's image I have a form, that contains 4 search criteria.
- Start Date
- End Date
- Number
- String (city name)
From those 4 fields, I'm trying to feed a Grid in the same page (in AJAX), with data that is coming from an WCF webservice.
I've tried several ways to achieve this but everytime I'm facing a dead-en.
Here's a sample of my code.
The form:
@using (Ajax.BeginForm("UpdateSearchCriteria", "Home", new AjaxOptions() { HttpMethod = "post", OnSuccess = "Update" }))
{
@(Html.Kendo().DatePickerFor(model => model.Criteria.StartDate)
.Min(new DateTime(1900, 1, 1)) //Set min date of the datepicker
.Max(new DateTime(2099, 12, 31)) //Set min date of the datepicker
)
@(Html.Kendo().DatePickerFor(model => model.Criteria.EndDate)
.Min(new DateTime(1900, 1, 1)) //Set min date of the datepicker
.Max(new DateTime(2099, 12, 31)) //Set min date of the datepicker
)
@(Html.Kendo().IntegerTextBoxFor(model => model.Criteria.Number).Min(1))
@(Html.Kendo().AutoCompleteFor(model => model.Criteria.CityName)
.Filter("contains")
.MinLength(3)
.BindTo(Common.Helpers.CityHelper.GetCityNames())
.HighlightFirst(true)
.IgnoreCase(true)
)
<
input
type
=
"submit"
value
=
"Search!"
/>
}
@(Html.Kendo().Grid<
Models.SearchResult
>()
.Name("SearchResultDataGrid")
.Columns(columns =>
{
columns.Bound(p => p.Property.PropertyName).Title("Property");
columns.Bound(p => p.Range).Title("Range");
columns.Bound(p => p.Number).Title("Number");
})
.Sortable()
.Scrollable()
.AutoBind(false)
.BindTo(Model.SearchResult)
.DataSource(dataSource => dataSource // Configure the grid data source
.Ajax() // Specify that ajax binding is used
.Read(read => read.Action("Search", "Home")) // Set the action method which will return the data in JSON format
)
)
JS Update method
<
script
>
function Update(response, status, data) {
var grid = $("#SearchResultDataGrid").data("kendoGrid");
grid.dataSource.read();
}
</
script
>
Now the controller:
public ActionResult UpdateSearchCriteria(Screen iModel)
{
return Json(iModel);
}
[HttpPost]
public ActionResult Search(Screen iModel)
{
[...]
return Json(theDataSourceRS);
}
Hope I was clear enough !
Let me know if you're missing parts to give me a hand !
Thanks a lot !
Julien.