locked
Data Annotations - Set Requiered to true for FirstName if Type = Standard RRS feed

  • Question

  • User749469198 posted

    Hi,

    i have a property FirstName in metadata class. I only want to set the "Required" Attributte to true if i select "Standard" in my Dropdownlist-Type - else not required.

    Can i achieve this in on FirstNameChanging or FirstNameChanged. Can someone point me in the right direction.

    Thanks

    Wednesday, January 30, 2013 5:21 AM

Answers

  • User1492915735 posted

    Responsiveness web app? If yes, Isn't the logic belong to client? Should not employing the javascript?

    Supporting Validation on the Client

    ASP.NET MVC supports client-side validation of data by sharing validation information from the server. This is done by implementing the IClientValidatable interface on your custom validation classes. IClientValidatable contains only the GetClientValidationRules method that returns a ModelClientValidationRule collection.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 31, 2013 8:32 PM

All replies

  • User3866881 posted

    FirstNameChanging

    Please do this event on FirstNameChanging to check your SelectedValue.

    And it would be better if you can define a customized Attribute to entitle which property you wanna do validation:

    http://msdn.microsoft.com/en-us/library/cc668224(v=VS.100).aspx

    Thursday, January 31, 2013 8:27 PM
  • User1492915735 posted

    Responsiveness web app? If yes, Isn't the logic belong to client? Should not employing the javascript?

    Supporting Validation on the Client

    ASP.NET MVC supports client-side validation of data by sharing validation information from the server. This is done by implementing the IClientValidatable interface on your custom validation classes. IClientValidatable contains only the GetClientValidationRules method that returns a ModelClientValidationRule collection.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 31, 2013 8:32 PM