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

2
  • Is your property SPEED nullable? Commented Nov 29, 2013 at 10:07
  • Would you like to make it not nullable? Commented Nov 29, 2013 at 10:48

1 Answer 1

1

Make target field as not nullable. It will put default value if value is not set.

Or implement custom Editor template:

http://buildstarted.com/2010/09/10/overriding-displayfor-and-editorfor-to-create-custom-outputs-for-mvc/

http://blogs.msdn.com/b/nunos/archive/2010/02/08/quick-tips-about-asp-net-mvc-editor-templates.aspx

Sign up to request clarification or add additional context in comments.

2 Comments

so is there a way to force this on the view ,, as i can not modify the DB design
Consider implementing custom Editor Templates blogs.msdn.com/b/nunos/archive/2010/02/08/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.