I'm having trouble in displaying validation message when a null value is selected.
My code for the dropdownlist:
<strong>@Html.ValidationSummary("", new { @class = "text-danger" })</strong>
@Html.DropDownList("Category", null, String.Empty, new { @class = "form-control" })
I understand that String.Empty equals to a null value(Correct me if i'm wrong).
My code for my model:
namespace Mp.Models
{
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public partial class Content
{
[Required(ErrorMessage: "A Category is required!")]
public string Category { get; set; }
}
}
ValidationMessage()helper? Does the html your generating include<option value=""></option>?Empty.Stringso the first value displayed on the dropdownlist would be blank.@Html.ValidationSummaryand not@ValidationSummary?