Hello,
said that I am new to Syncfusion asp.net core (I used a lot WPF controls, anyway) and to asp.net core itself, I am trying to use a datagrid in a page to display data from a collection of objects which is a property of the page model.
The collection in my model is like:
public class Visite
{
[ ... ]
public int Id { get; set; }
public string VisitId { get; set; }
public List<OperazioniVisita> Operazioni { get; set; } = new List<OperazioniVisita>();
public DateTime DataProgrammata { get; set; }
public DateTimeOffset TimestampRegistrazione { get; set; }
public string UsernameRegistrazione { get; set; }
[ ... ]
}
OperazioniVisita is the following model:
public class OperazioniVisita
{
public long Id { get; set; }
public long IdVisita { get; set; }
public string CodiceImballo { get; set; }
public int NumeroMovimentazioni { get; set; }
public int NumeroAperture { get; set; }
}
In the Controller I have:
public async Task<IActionResult> EditDetailsVisit(string index)
{
try
{
HttpClient client = new HttpClient();
HttpRequestMessage request = [ ... ]
[ ... ]
Visite v = null;
var resp = await client.SendAsync(request);
if (resp.IsSuccessStatusCode)
{
string res = await resp.Content.ReadAsStringAsync();
v = JsonConvert.DeserializeObject<Visite>(res);
}
[ ... ]
to render the view, and:
public async Task<IActionResult> SaveDetailsVisit(Visite visita, string save)
{
[ ... ]
}
for the post back.
In the .cshtml I have:
<div class="col-lg-9 control-section">
@{
var ImballiDropDownList = new Syncfusion.EJ2.DropDowns.DropDownList()
{
DataSource = @NewVisitViewModel.Imballi,
Query = "new ej.data.Query()",
AllowFiltering = true,
Fields = new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings() { Value = "Codice", Text = "Descrizione" },
BeforeOpen = "beforeOpen"
};
}
[ ... ]
<ejs-grid id="Grid" dataSource="@Model.Operazioni"
toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })"
allowPaging="true">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" newRowPosition="Top"></e-grid-editSettings>
<e-grid-pagesettings pageCount="5"></e-grid-pagesettings>
<e-grid-columns>
<e-grid-column field="Id" headerText="Op. ID" visible="false"></e-grid-column>
<e-grid-column field="IdVisita" headerText="Visit Id" visible="false"></e-grid-column>
<e-grid-column field="CodiceImballo" headerText="Imballo" textAlign="Center" dataSource="@NewVisitViewModel.Imballi"
foreignKeyField="Codice" foreignKeyValue="Descrizione"
editType="dropdownedit" edit="@(new { @params = ImballiDropDownList } )">
</e-grid-column>
<e-grid-column field="NumeroMovimentazioni" headerText="Movimentati"
textAlign="Center" width="120"
validationRules="@(new { required=true, number=true})">
</e-grid-column>
<e-grid-column field="NumeroAperture" headerText="Aperti"
textAlign="Center" width="100"
validationRules="@(new { required=true, number=true})">
</e-grid-column>
</e-grid-columns>
</ejs-grid>
[ ... ]
When the page appears everything is fine and the items of the model property "Operazioni" are visibile:
I can also add, inline edit or delete rows without any problem.
But in my page I also have other data and a submit button to post back data to the controller. When I do the post back, the model is posted back with the Operazioni property in the posted back model is empty:
Now, I am sure this is because I am missing something big... but I read a lot of threads in your forum and all the samples in the datagrid documentation without reaching a point.
but I wasn't able to adapt these solutions to my case.
Could you please give me a hand ?
Thank you
Giacomo