-1

I know the dropdown list data is coming from the viewBag not model , thats why model doesnt validate the particular dropdown list while it validates other fields which are linked to model, Just want to know, how can i validate the above dropdownlist

This doesnt works on (ModelState.IsValid)

Controller

var td = tabladatos.GetAll();
var estadossol = (from item in td
                  where item.Relacion == "EstadoSolicitud" && !(item.Valor == 1 || item.Valor == 3 || item.Valor == 4 || item.Valor == 5)
                  orderby item.Orden ascending
                  select item).ToList();

ViewBag.EstadoSolicitud = new SelectList(estadossol, "Valor", "Descripcion", "2");

View

@Html.DropDownList("EstadoSolicitud", null, "", new { @class = "select2_single form-control" })
@Html.ValidationMessageFor(model => model.EstadoSolicitud)
Alex Fariñas
  • 97
  • 1
  • 2
  • 7
  • Check [Here](http://forums.asp.net/t/1900637.aspx?jQuery+Validate+Unobtrusive+no+validation+message+for+dropdown). I guess this is what you need. – Helen Araya Jul 18 '16 at 17:06
  • Please note that the model-view-controller tag is for questions about the pattern. There is a specific tag for the ASP.NET-MVC implementation. –  Jul 18 '16 at 22:18
  • Possible duplicate of [Will there be any conflict if i specify the viewBag name to be equal to the model property name inside @Html.DropDownListFor](http://stackoverflow.com/questions/37161202/will-there-be-any-conflict-if-i-specify-the-viewbag-name-to-be-equal-to-the-mode) –  Jul 18 '16 at 22:19

1 Answers1

0

You can bind the selected value of the dropdown to a value in your model, and then display a message for that.

Model

[Required]
public int? SeleccionadoValor { get; set; }

Razor

@Html.DropDownListFor(m => m.SeleccionadoValor, ViewBag.EstadoSolicitud)
@Html.ValidationMessageFor(model => model.SeleccionadoValor)
Will Ray
  • 10,621
  • 3
  • 46
  • 61