1

Ive got an Html.TextBoxFor that is used to represent a Double. When I generate "Create" View

@Html.TextBoxFor(Function(model) model.Longitude)

The <input> has a default value of "0"

I have tried modifying it in two ways

@Html.TextBoxFor(Function(model) model.Longitude, New With {.value = ""})

and in the controller

Dim model As Domain.Event = New Domain.Event
With model
    .Longitude = String.Empty
End With

Return View(model)

But neither of these work.

How can I have the input "Blank" for a numeric input?

Chase Florell
  • 46,378
  • 57
  • 186
  • 376

2 Answers2

3

You could use a Nullable(Of Double) type or double? in C#.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • @rockinthesixstring, thanks for the info. Didn't know this. It's good to hear that VB.NET has also syntactic sugar support for nullable types. I will have to refresh my old VB.NET skills :-) – Darin Dimitrov Nov 24 '10 at 18:53
  • You can also use **Automatic Properties** in VB. `Public Something As String` – Chase Florell Nov 24 '10 at 18:54
0

Look at answer of this question

They overwrite default values in model binding.

You can derive your custom model binder from DefaultModelBinder. You can add as many other Binders as you need.

Example: Register your Binder in global.asax in such way

protected void Application_Start() { ... your code ... ModelBinders.Binders.DefaultBinder = new YourModelBinder(); .... your code... }

Community
  • 1
  • 1
arena-ru
  • 990
  • 2
  • 12
  • 25