What answers better to give from the server?

Here's an example
[HttpPost]
 public ActionResult Create(ViewModel vm)
{
 if (ModelState.IsValid)
{
 var model = Mapper.Map<viewmodel, post>(vm);
ps.CreatePost(model);
ps.SavePost();
 RedirectToRoute("Slug", new { controller = "Log", action = "Details", id = model.Id, slug = model.Slug });
}
 return View(vm);
 }</viewmodel>

Here almost everything is clear...
But then
public ActionResult Edit(int? id)
{
 if (id == null)
{
 return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
 Post model = ps.GetPostById(id.Value);
 if (model == null)
{
 return HttpNotFound();
}
 var vm = Mapper.Map<post, postviewmodel>(model);
 return View(vm);
 }</post>

Whether, when a blank identifier, we receive bad request and not when the model is 404?
Is there any template? best practices?
July 2nd 19 at 17:43
2 answers
July 2nd 19 at 17:45
Solution
All right. If you think about the meaning of the method, he should get the record id and returns either its contents or the flag of its absence.

If you replace int? to int and remove the first check, the app will work exactly the same, but the error handling will be done automatically by the framework. He will look for a method with the appropriate signature, you will not find it and will give you a standard error message.

Thus, a zero value id logic does not matter - it is made to demonstrate how to handle errors manually.
July 2nd 19 at 17:47
Not correct to compare the Create and Edit. To Edit questions arise IMHO is correct and understandable.

Find more questions by tags ASP.NETC#