Using HTML, create an empty textbox. An EF entity's TextBoxFor on a not-null attribute

asp.net-mvc-2 entity-framework

Question

Entity Framework (v4) entities are what I'm utilizing. I have a Car entity that has an integer-type Year attribute. There is no room for NULL in the Year attribute. The following is what my Create view displays:

<%= Html.TextBoxFor(model => model.Year) %>

Due to other needs, I must return a new Car object in the CarController's HttpGet Create call.

The Year textbox now shows a zero since the Year attribute does not permit NULL. In the Create view, I want an empty textbox to be shown. What should I do?

1
19
4/24/2010 9:07:41 AM

Popular Answer

Use an overload of HTML attributes. This would be in razor:

@Html.TextBoxFor(model => model.Year, new { Value = "" })
45
5/31/2011 11:02:21 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow