when deciding on which ActionResult to return from a Controller Action I decided to use the ternary operators as opposed to the lengthier if-else. Here is my issue...
this code works
return
ModelState.IsValid ?
(ActionResult) RedirectToAction("Edit", new { id = id }) :
View(new EditViewModel(updatedCategory));
but this doesn't
return
ModelState.IsValid ?
RedirectToAction("Edit", new { id = id }) :
View(new EditViewModel(updatedCategory));
I would not have to do the explicit casting if using an if-else. Plus both RedirectToAction() and View() return an ActionResult derivative.
I like the terseness of this code but that casting doesn't seem right. Can anyone enlighten me?
Though I'm sure this is obvious, the EditViewModel is a view model for my Edit action and updatedCategory is an EF4 object. But I don't think this is relevant to the issue.
ok... I just realized what I was doing is unnecessary because regardless I am going back to the Edit action with the updatedCategory, so I don't need to make sure the Model is valid. I am still curious to know the answer to the question if anyone can help.