I wanted to know how to loop to print the columns of my grid with the values of the database, but it only showed 1 result even the database being huge, here is the code, thanks for the help
CONTROLLER:
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web.Mvc;
using TelerikMvcApp1.Models;
namespace TelerikMvcApp1.Controllers
{
public partial class GridController : Controller
{
public ActionResult GetContacts()
{
SqlConnection conexao = new SqlConnection(@"meubancodedados");
conexao.Open();
string strQuerySelect = "SELECT * FROM PessoaFisica";
SqlCommand cmdComandoSelect = new SqlCommand(strQuerySelect, conexao);
SqlDataReader dados = cmdComandoSelect.ExecuteReader();
while (dados.Read())
{
var contacts = new List<OrderViewModel>
{
new OrderViewModel {CompanyName = "Alabaster Almonds", ContactName = "Alex Allentown", Nome = dados["nome"].ToString()},
};
return Json(contacts);
}
return GetContacts();
}
}
}
VIEW:
@model TelerikMvcApp1.Models.OrderViewModel
@using TelerikMvcApp1.Models
@(Html.Kendo().Grid<OrderViewModel>()
.Name("ExampleGrid")
.Columns(columns =>
{
columns.Bound(c => c.ContactName).Width(140);
columns.Bound(c => c.CompanyName);
columns.Bound(c => c.Nome);
})
.DataSource(s => s.Ajax().Read(r => r.Action("GetContacts", "Example")))
)
<script>
$.ajax({
type: "POST",
url: "Grid/GetContacts",
dataType: "json",
data:{data:'B'},
success: function (data) {
$("#ExampleGrid").data("kendoGrid").dataSource.data(data);
},
});
</script>