Let's say I have a class like this
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime BirthDate { get; set; }
public List<Work> Employments { get; set; }
}
public class Work
{
public string Employer { get; set; }
public int Salary { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
My controller have both HttpGet and httpPost for Edit
[HttpGet]
public IActionResult Edit(int id)
{
var _item = new Person()
{
Id = id,
Name = "Bob",
BirthDate = new DateTime(1970, 3, 4),
Employments = new List<Work>()
{
new Work(){ Employer="Microsoft", Salary=5000, StartDate= new DateTime(1998, 1, 1), EndDate=new DateTime(2005, 12, 31)},
new Work(){ Employer="Google", Salary=6000, StartDate= new DateTime(2006, 1, 1), EndDate=new DateTime(2013, 12, 31)},
new Work(){ Employer="Spotify", Salary=10000, StartDate= new DateTime(2014, 1, 1)}
}
};
return View(_item);
}
[HttpPost]
public IActionResult Edit(Person _item)
{
return View(_item);
}
and my Edit.csthml looks like
@Model Person
<form asp-action="Edit">
<div class="form-group">
<label asp-for="Name" class="control-label"></label>
<input type="string" asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="BirthDate" class="control-label"></label>
<input type="date" asp-for="BirthDate" class="form-control" />
<span asp-validation-for="BirthDate" class="text-danger"></span>
</div>
<GRID>
table with the rows of Work
</GRID>
<button type="submit" class="btn-primary">Send</button>
</form>
I don't know how to get the Grid part, all example I see are the grid standalone or have own AJAX request, not part of the other properties.
In old asp.net WebForms you could have it in one update.
So how do you do things like this in .NET Core?
The question is NOT part of the update in database, I use Dapper and stored procedures, not EF Core...
The question is how to retrieve the edited data to my generic class before DB-update...
