Reputation: 1
I have the following code inside my razor _CreateOrEdit view :-
@Html.EditorFor(model =>model.SystemInfo.ProcessorInfoes.FirstOrDefault().SPEED)
But i need to display the value of zero incase the model.Speed is null, baring in mind that i am sing the same code in my Create and Edit view ?
Thanks
Upvotes: 1
Views: 766
Reputation: 44550
Make target field as not nullable. It will put default value if value is not set.
Or implement custom Editor template:
http://blogs.msdn.com/b/nunos/archive/2010/02/08/quick-tips-about-asp-net-mvc-editor-templates.aspx
Upvotes: 1