how to make a field mandatory

Asked

Viewed 238 times

1

I’m maintaining a page using Asp.net MVC and using Kendo Asp.Net MVC and I need to make two fields mandatory, but I’m not getting it

index.cshtml:

    <div class="col-lg-2 demo-section k-content" id="dayId">
        <label class="control-label">@Messages.TotalSwitching_Date - @Messages.TotalSwitching_Start</label>
        @(Html.Kendo().DatePicker()
          .Name("firstDay")
          .Events(e => e.Change("firstDayChange"))
          .Start(CalendarView.Month)
          .Depth(CalendarView.Month)
          .Format("MM dd yyyy")
          .HtmlAttributes(new { style = "width: 50%" })
          .Value(ViewBag.FirstDate)
          .Min(ViewBag.FirstDate)
          .Max(ViewBag.LastDate)
        )
        <label class="control-label">@Messages.TotalSwitching_Date - @Messages.TotalSwitching_End</label>
        @(Html.Kendo().DatePicker()
          .Name("lastDay")
          .Events(e => e.Change("lastDayChange"))
          .Start(CalendarView.Month)
          .Depth(CalendarView.Month)
          .Format("MM dd yyyy")
          .HtmlAttributes(new { style = "width: 50%" })
          .Max(ViewBag.LastDate)
          .Min(ViewBag.FirstDate)
        )
    </div>
  • 1

    Just define in the model that the attribute cannot be null.

1 answer

1


In your model you can set your attribute to Required, just insert the TAG [Require] and import Dataannotations.

Example: [Required] public string Nome { get; set; }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.