0

I am generating Form elements using a Model Class as below

Public Class BookAppointment
    Property DoctorNin As Integer
    Property PatientNin As Integer
    Property BookingDate As Date

    Property Doctors As IEnumerable(Of SelectListItem)
End Class

When I pass this View Model to the view page, some of the values are already there as default value but they are invalid.

Like for PatientNin I use

<%= Html.TextBoxFor(Function(x) x.PatientNin)%>   

When the form gets rendered, it get a 0 as a default value, which is unwanted. How to control such default values?

In the above case, same happens with BookingDate and in the textbox I get 1/1/0001 12:00:00 AM Which is out of format and unwanted default value?

How to solve problem like this?

tereško
  • 58,060
  • 25
  • 98
  • 150
mrN
  • 3,734
  • 15
  • 58
  • 82

2 Answers2

0

The default value of an integer type will be zero. So if you are not assigning any values to it. It will bring zero as the value.

If you do not want the default zero value, you can switch your property to Nullable type.

Shyju
  • 214,206
  • 104
  • 411
  • 497
0

Changes default value to 100 if its not greater than 0:

<%= Html.TextBoxFor(Function(x) If(x.PatientNin > 0, x.PatientNin, 100))%> 
NoAlias
  • 9,218
  • 2
  • 27
  • 46
  • I got an error `Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.` – mrN Aug 27 '12 at 02:17