I have inline editing grid which using foreign key column. In the foreignKey.cshtml i also add the option label (“Please select”).
Views:
columns.ForeignKey(p => p.EmployeeID, (System.Collections.IEnumerable)ViewData["testStatus"], "EmployeeID", "EmployeeName");
Model:
[Required(ErrorMessage = "Required")]
[DisplayName("Employee ")]
[UIHint("GridForeignKey")]
public int EmployeeID { get; set; }
Shared/GridForeignKey.cshtml
@(
Html.Kendo().DropDownList()
.Name(ViewData.TemplateInfo.GetFullHtmlFieldName(""))
.BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
.OptionLabel("Select value")
)
My question is, how i can validate if the user choose “Please select” option and display required message. THank you
Thank you
Try adding the range attribute instead of required to the model. More than likely your first item is of “please select” is being given a value of 0 or “please select” so the required attribute won’t do what you need since technically that input has a value.
Also try add a selected index to your drop down list assuming you don’t already have a selected value.