Ok I am working a problem regarding a web form built off Kendo (which i am very much still new to) the form in question has some fields which only appear under certain conditions. When they are visible they need to be required fields but when not visible they need to be ignored. I have been going through the code and have traced back to a CSHTML file that designates when these fields become visible. which i have posted below

    @model PhoenixOnlineMVC.Areas.EventManagement.Models.CompetitionPlannedElementItem
<script type="text/javascript">
     @Html.Raw(Model.Code)
</script>
<tr style="vertical-align: top;">
<td>@Model.Index</td>
<td>@(Html.Kendo().DropDownListFor(m => m.SelectedTypeId)
          .HtmlAttributes(new { style = "width:120px" })
          .DataTextField("Text")
          .DataValueField("Value")
          .BindTo(Model.Types)
          )</td>
<td>@(Html.Kendo().DropDownListFor(m => m.SelectedElementId)
           .HtmlAttributes(new { style = "width:160px" })
           .DataTextField("Text")
           .DataValueField("Value")
           .Events(events => events.Select(@Model.SelectedFunctionName))
           .DataSource(source => source.Read(read => read.Action("GetCascadeElements", "Event")
                                                           .Data(@Model.DataFunctionName))
                                        .ServerFiltering(true))
           .Enable(false)
           .AutoBind(false)
           .CascadeFrom(@Model.TypeComboBoxName)
           )</td>
<td style="width: 130px; overflow: auto">
    @{
              const string htmlHiddenAttributes = "width:120px; margin: 2px 4px 4px 0; display:none; ";
              const string htmlVisibleAttributes = "width:120px; margin: 2px 4px 4px 0;";

              if (Model.SelectedSuppElementId1 != null) 
                  { 
                      @Html.DropDownListFor(m => m.SelectedSuppElementId1, Model.SuppElements1, new { style = htmlVisibleAttributes })

                  }
              else
                  {
                      @Html.DropDownListFor(m => m.SelectedSuppElementId1, Model.SuppElements1, new { style = htmlHiddenAttributes })
                  }
              if (Model.SelectedSuppElementId2 != null)
                  {
                      @Html.DropDownListFor(m => m.SelectedSuppElementId2, Model.SuppElements2, new { style = htmlVisibleAttributes })
                  }
              else
                  {
                      @Html.DropDownListFor(m => m.SelectedSuppElementId2, Model.SuppElements2, new { style = htmlHiddenAttributes })
                  }
              if (Model.SelectedSuppElementId3 != null)
                  {
                      @Html.DropDownListFor(m => m.SelectedSuppElementId3, Model.SuppElements3, new { style = htmlVisibleAttributes })
                  }
              else
                  {
                      @Html.DropDownListFor(m => m.SelectedSuppElementId3, Model.SuppElements3, new { style = htmlHiddenAttributes })
                  }
              if (Model.IsTransition)
                  {
                      @Html.TextBoxFor(m => m.TransitionText, new { style = htmlVisibleAttributes })
                  }
              else
                  {
                      @Html.TextBoxFor(m => m.TransitionText, new { style = htmlHiddenAttributes })
                  }
          }
</td>
</tr>
    @Html.HiddenFor(m => m.Index)
    @Html.HiddenFor(m => m.CompetitionPlannedElementId)
    @Html.HiddenFor(m => m.CompetitionSkatedEventId)
    @Html.HiddenFor(m => m.SanctionPlannedElementId)
    @Html.HiddenFor(m => m.IsTransition)

I am interested in the @Html.DropDownListFor components Is there a way to add a required field to these? or possibly just in that part of the if statements?

Related posts

Recent Viewed