I have a form that is being used to edit existing object as well as to enter a new one.
When I am using it to edit, i pass the model to the view inside the action like this
return View("Details", myModelObject);
When I am using the Details view to enter the new object, I am not passing anything
return View("Details");
I am getting en error because the framework expects the model to be passed in as at the beggining of the view I have
@model myApp.Models.myModel
One way to get around is to pass an empty model, but this seems kind of awkward and unnecessary. Is there a way to indicate that @model is optional?
This is the correct way. Your view expects a model. Since this view is intended for creating a new model, passing a new instance of the model is very natural: