0
wanted to know how to loop when printing the columns of my grid with the values of the database, but it displayed only 1 result even the database being huge, here 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>
even so my view does not appear anything in the list, even the database having things to read, the loop still does not work.
– Marcelo Henrique Dos Reis
@Marcelohenriquedosreis That’s why you did something wrong...
– Jéf Bueno
now that I saw that the view problem was something else, your code was right, vlwzao <3
– Marcelo Henrique Dos Reis