Let's assume, you are dealing with a "person" entity in mvc. Think about the data flow when you use a "create" scaffold: when you call the
action (the HttpGet edition of it), you will probably just make a simple
. Ok, the view is rendered, and you get the html code. Yes, the view is referencing the model, but it is only reflected, you don't have a model object, just the model type. Of course, there could be a DefaultValue
] attribute for that, but it's for something else. It could be used by the helper, but it is not.
Well, you still don't know what to do...
Ok, remember what you are usually doing in the HttpPost version of the NewPerson action. You get the model populated with an instance, you validate it, and if the validation fails, you pass the model object to the same view. And wow, you the rendered html will have the values. Well, why don't use the same concept in the HttpGet version as well?
So: simply create a model object, fill it with the default values. Of course you can add a constructor to the model class and set these values there. (You could add default values, if you would use public fields instead of public properties, but I suggest you don't). And pass this newly created object filled with the defaults to the view.