Hello,
I'm trying to develop a search form that will load datas from a stored procedure into a Kendo UI Grid item....
I've some problem passing back the Model to the Action Method in the controller...
Here's my view code
The RicercaController
And the models
How do I pass back the Model without using a js function and create a javascript object?
Thanks
I'm trying to develop a search form that will load datas from a stored procedure into a Kendo UI Grid item....
I've some problem passing back the Model to the Action Method in the controller...
Here's my view code
@model DemoRicerca_Interno.Models.RicercaClienteObject
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<
div
>
<
div
id
=
"ricerca"
></
div
>
<
div
>Query : @Html.EditorFor(x => x.Query)</
div
>
<
div
>Match Exact : @Html.EditorFor(x => x.MatchExact)</
div
>
<
div
>AncheEstinti : @Html.EditorFor(x => x.AncheEstinti)</
div
>
<
button
id
=
"showGrid"
>Carica</
button
><
br
/>
<
script
type
=
"text/javascript"
>
$("#showGrid").click(function () {
$("#grid").data("kendoGrid").dataSource.read();
});
</
script
>
<
div
id
=
"content"
>
@(Html.Kendo()
.Grid<
DemoRicerca_Interno.Models.Rapporto
>()
.AutoBind(false)
.Name("grid")
.Columns(columns =>
{
columns.Bound(x => x.IDInterno).Visible(false);
columns.Bound(x => x.IDRapporto);
columns.Bound(x => x.Descr);
columns.Bound(x => x.Filiale);
columns.Bound(x => x.RM);
columns.Bound(x => x.NDG);
})
.DataSource(ds => ds
.Ajax()
.Read(read =>
{
read.Action("GetClienti", "Ricerca");
//new DemoRicerca_Interno.Models.RicercaClienteObject { Query = Model.Query, MatchExact = Model.MatchExact, AncheEstinti = Model.AncheEstinti });
}
)
)
)
</
div
>
</
div
>
public
class
RicercaController : Controller
{
public
ActionResult Index()
{
ViewData.Model =
new
RicercaClienteObject();
return
View();
}
public
ActionResult GetClienti([DataSourceRequest] DataSourceRequest request, RicercaClienteObject ricerca)
{
xxxEntities model =
new
xxxEntities();
var res = model_SP_GET_INTESTATARIO(xxx, ricerca.Query, ricerca.MatchExact, xxx, DateTime.Now.AddDays(-1), 0, ricerca.AncheEstinti,
null
,
null
);
List<Rapporto> lst =
new
List<Rapporto>();
foreach
(var item
in
res)
{
var rapporto =
new
Rapporto();
rapporto.Descr = item.INTESTAZIONE.Trim();
rapporto.Filiale = item.FILIALE.Trim();
rapporto.IDRapporto = item.CODICE_RAPPORTO.Trim();
rapporto.NDG = item.NDG.Trim();
rapporto.RM = item.RM.Trim();
rapporto.IDInterno = item.ID_RAPPORTO;
lst.Add(rapporto);
}
var result = lst.ToDataSourceResult(request);
return
Json(result);
}
}
public
class
RicercaClienteObject
{
[DataType( System.ComponentModel.DataAnnotations.DataType.Text)]
public
string
Query {
get
;
set
; }
public
int
AncheEstinti {
get
;
set
; }
public
int
MatchExact {
get
;
set
; }
}
public
class
Rapporto
{
public
string
IDRapporto {
get
;
set
; }
public
string
Descr {
get
;
set
; }
public
int
? IDInterno {
get
;
set
; }
public
string
Filiale {
get
;
set
; }
public
string
RM {
get
;
set
; }
public
string
StatoRapporto {
get
;
set
; }
public
string
NDG {
get
;
set
; }
public
string
Servizio {
get
;
set
; }
public
int
? IDCliente {
get
;
set
; }
}
Thanks