You can have following logic in place:
For entity that you save, keep an ID as one of the parameter (mapped to unique field in DB). Don't make this field as mandatory for model validation.
Now, whenever it's a new entity for insert, this ID would be null and defined once inserted in DB. If an entity is being updated, this ID will have some data mapping to existing data in DB.
You can use this ID field value as a flag to know and implement if it should be insert or update flow. Keep this ID field as hidden field in your view:
@Html.HiddenFor(m => m.Id)
Your controller code would change to:
if (ModelState.IsValid)
{
if (!model.Id.HasValue){
{
} else {
}
}
Try out.
BTW, you should keep insert & update separate and have single responsibilities for each flow from controller method point of view. It's cleaner. Examples:
Tutorial: Implement CRUD Functionality with the Entity Framework in ASP.NET MVC | Microsoft Docs[
^]
Perform List, Insert, Update and Delete in a Single View in ASP.NET MVC | BinaryIntellect Knowledge Base[
^]