I think what you want is something like the following, please check it.
My project structure.
]2
Test Code
public IActionResult CreateOrUpdate(string id)
{
if (id == null || id.Equals(string.Empty))
{
// Create a new model
ViewBag.Title = "Create a new model";
return View();
}
else {
// Update the exist model
Actor editModel = new Actor
{
ProfilePictureURL="test.url",
FullName= "test FullName",
Bio = "test Bio",
Id = "001"
};
ViewBag.Title = "Update exist Actor model";
return View(editModel);
}
}
CreateOrUpdate.cshtml
@model Actor
@{
ViewData["Title"] = ViewBag.Title;
}
<div class="row text">
<div class="col-md-8 offset-2">
<p>
<h1>@ViewBag.Title</h1>
</p>
<div class="row">
<div class="col-md-8 offset-2">
<form class="row" asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="mb-3">
<label asp-for="ProfilePictureURL" class="form-label"></label>
<input asp-for="ProfilePictureURL" type="text" class="form-control" />
<span asp-validation-for="ProfilePictureURL" class="text-danger"></span>
</div>
<div class="mb-3">
<label asp-for="FullName" class="form-label"></label>
<input asp-for="FullName" type="text" class="form-control" />
<span asp-validation-for="FullName" class="text-danger"></span>
</div>
<div class="mb-3">
<label asp-for="Bio" class="form-label"></label>
<input asp-for="Bio" type="text" class="form-control" />
<span asp-validation-for="Bio" class="text-danger"></span>
</div>
<div class="mb-3">
<input type="submit" value="Create" class="btn btn-outline-success float-end" />
<a class="btn btn-outline-secondary" asp-action="Index"> Show All</a>
</div>
</form>
</div>
</div>
</div>
</div>
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards
Jason