Hi,
In my Index.cshtml file, I have the following code:
@using (Html.BeginForm("Index", "Home", FormMethod.Post,
new
{
id = "FormID"
}))
{
<fieldset>
<legend>Dist</legend>
@(Html.Telerik().ComboBox()
.Name("ComboBox")
.BindTo((IEnumerable<DropDownItem>)ViewData["Dist"])
.ClientEvents(events => events.OnChange("ComboBox_onChange"))
)
@(Html.Telerik().Grid(Model)
.Name("grid")
.Columns(columns =>
{
columns.Bound(o => o.OrderId).Width(40);
})
.DataBinding(dataBinding => dataBinding.Ajax().Select("OrderList()", "Home"))
.Render()
)
</fieldset>
}
Also, the following javascript:
<script type="text/javascript">
function ComboBox_onChange(e) {
var combobox = $(this).val();
var grid = $("#grid").data("tGrid");
$.ajax({
type: 'POST',
url: 'http://localhost:54721/Home/OrderList',
data: "{'Id':'" + combobox + "'}",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(data){
$("#grid").dataBind(data);
},
error: OnError
});
}
function OnError(request, status, error) {
if (x.status == 0) {
alert('You are offline!!\n Please Check Your Network.');
} else if (x.status == 404) {
alert('Requested URL not found.');
} else if (x.status == 500) {
alert('Internel Server Error.');
} else if (e == 'parsererror') {
alert('Error.\nParsing JSON Request failed.');
} else if (e == 'timeout') {
alert('Request Time out.');
} else {
alert('Unknow Error.\n' + x.responseText);
}
}
function Grid_onDataBinding(e) {
var grid = $(this).data('tGrid');
$.ajax({
type: 'POST',
url: 'http://localhost:54721/Home/OrderList',
data: "{'Id':'" + combobox + "'}",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (data) {
$("#grid").dataBind(data);
},
error: OnError
});
}
</script>
In the controller file, I have this:
public ActionResult Index()
{
//ViewBag.Message = "Welcome to ASP.NET MVC!";
//ViewBag.Dist = GetDistList();
var dist = from p in Distributor.DistributorList()
select new Telerik.Web.Mvc.UI.DropDownItem
{
Text = p.Text,
Value = p.Value
};
ViewData["Dist"] = dist.ToList();
return View();
}
The drop down works fine. What I want to do is when the user pick an record/item from the dropdown, it calls an action from the controller, and populate the grid. I can see it gets the data but the grid does not show up. What did I do wrong? Thanks for your help.