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

asp.net-mvc-2 entity-framework

Question

I am using Entity Framework (v4) entities. I have an entity called Car with a Year property of type integer. The Year property does not allow NULL. I have the following in my Create view:

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

I am required to return a new Car object (due to other requirements) in my HttpGet Create action in the CarController.

Currently, a zero is displayed in the Year textbox because the Year property does not allow NULL. I would like to display an empty textbox in the Create view. How do I do this?

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

Popular Answer

Use Html Attributes Overload. In razor it would be:

@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