jwaliszko / ExpressiveAnnotations

Annotation-based conditional validation library.
MIT License
351 stars 123 forks source link

Learning ExpressiveAnnotations - RequiredIf doesn't display the error message #211

Open BeautifulLifeIsGood opened 2 years ago

BeautifulLifeIsGood commented 2 years ago

Hello, I downloaded the ExpressiveAnnotations and tried to implement it in my project. Having trouble getting it to work. The validation message didn't appear. Thank you for your help.

Here is what I got:

[DisplayName("Company Name")] [RequiredIf("Search_Profile_Type == 'EMPLOYER'")]

public string Search_Company { get; set; }


@Html.ValidationSummary(true, "", new { @class = "text-danger" })

@Html.LabelFor(m => m.Search_Profile_Type, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.DropDownListFor(m => m.Search_Profile_Type, new List { new SelectListItem{ Text="ALL", Value = "ALL" }, new SelectListItem{ Text="Adjuster (Person)", Value = "ADJUSTER" }, new SelectListItem{ Text="Attorney (Person)", Value = "ATTORNEY" }, new SelectListItem{ Text="Carrier, Self-Insured Employer, Fund (Company)", Value = "CARRIER" }, new SelectListItem{ Text="Employer Contact Person (Person)", Value = "EMP_CONT" }, new SelectListItem{ Text="Employer (Company)", Value = "EMPLOYER" }, new SelectListItem{ Text="Injured Employee (Person)", Value = "IE" }, new SelectListItem{ Text="Other Contact Person (Person)", Value = "OTHERCONT" }, new SelectListItem{ Text="Other Company (Company)", Value = "OTHERCOMP" }, new SelectListItem{ Text="Rehab Provider Company (Company)", Value = "REHABCO" }, new SelectListItem{ Text="Rehab Provider Contact Person (Person)", Value = "RHC_CONT" }, new SelectListItem{ Text="Rehab Provider (Person)", Value = "QRP" }, new SelectListItem{ Text="Third Party Administrator (Company)", Value = "TPA" }, new SelectListItem{ Text="Vendor (School, Bookstore, Training Facility, etc.) (Company)", Value = "VENDOR" }, new SelectListItem{ Text="Vendor Contact Person (Person)", Value = "VEND_CONT" }}, new { @class = "form-control", @style = "max-width:400px;height:35px;resize:horizontal" })
<div class="form-group">
    @Html.LabelFor(m => m.Search_Company, htmlAttributes: new { @class = "control-label col-md-2", id = "Search_Company_Label" })
    <div class="col-md-10">
        @Html.TextAreaFor(m => m.Search_Company, new { @class = "form-control", @style = "max-width:400px;height:35px" })
        @Html.ValidationMessageFor(m => m.Search_Company, "", new { @class = "text-danger" })
    </div>
</div>