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?

2 Answers 2

3

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

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

2 Comments

@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 :-)
You can also use Automatic Properties in VB. Public Something As String
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... }

Comments

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.