Pergunta

I need to implement following validations in MVC

1. Date field

  1. A field can accept only mm/dd/yyyy format and should be in a year range between 1753-9999 and other basic checks like Leaf year and 30, 31 days

  2. Sometimes a field can accept a text 'N/A'(not applicable)

  3. Also date should be greater than start date.

2. Numeric field

  1. Should accept valid numbers from 1 to 100 , if decimal 0.1 to 99.99

  2. Can accept N/A

3. Dependency Field

This field is required only if another field has a value.

4. Triggers

  1. If this field value is A->B then it should affect other field values that are editable.

    Is there any library for MVC 3 supports all? Or do i combine Foolproof and standard MVC validations? Any suggestion for implementing my above needs?

Foi útil?

Solução

Why don't you take advantage of HTML5

for Time

 @Html.TextBox("timeFrom", DateTime.Now.AddHours(2).ToString("HH:mm"), new { type = "time", size = 3, step = "1" })

for date

@Html.TextBox("Mydate", new { required = "required", type="date" })

for number

<input type="number" name="quantity" min="1" max="100">
@Html.TextBox("number", new {type="number" name="quantity" min="1" max="100"})

for dependency field you can use system.componentmodel. data annotations

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top