Hello All,
I have a dropdown list in MVC view that is binded from a database. I'm passing an additional 1 item with text as "Please select" and value as "" but this is not getting validated at the client-side.
please find my code below.
Model
public class tbl_SubmittedDesignValidation
{
[Required]
[Range(1, 100, ErrorMessage = "Please select a Production Line")]
public Nullable<int> ProductionLine { get; set; }
}
Controller
public ActionResult Create(string LocationCode)
{
ViewBag.ProductionLine = new SelectList(db.tbl_ProductionLines, "Code", "Description");
return View();
}
View
@Html.DropDownList("ProductionLine", null, "Please select", htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.ProductionLine, "", new { @class = "text-danger" })
Can anyone please point me, where I'm doing a mistake.
Thanks