Assume a simple model:
public class PostViewModel
{
[DataType(DataType.Date)] public DateTime Start { get; set; }
[DataType(DataType.Date)] public DateTime End { get; set; }
}
and a GET and a POST action:
[HttpGet]
public IActionResult Edit(PostViewModel viewModel)
{
return View(viewModel);
}
[HttpPost]
[ActionName(nameof(Edit))]
public IActionResult EditPost(PostViewModel viewModel)
{
viewModel.Start = DateTime.Today;
viewModel.End = DateTime.Today.AddDays(7);
return View(viewModel);
}
The response of the post always returns the posted values and not the ones manually set by me:
How to fix this behavior?