Asp.Net MVC 2 LabelFor Custom Text

后端 未结 4 2037
南旧
南旧 2021-01-01 17:39

Is there a way to use the LabelFor helper and customize the label text without having to use the DisplayNameAttribute in my model?

4条回答
  •  萌比男神i
    2021-01-01 18:31

    I have found this extemely useful. I think this is something missing from MVC 2. Or at least I have not found a way to do it built in.

    The simplest case details the need for this feature. I have two objects Contacts and Addresses. A Contact can have multiple Addesses

    Address

    • ID
    • Street
    • City
    • State

    Contact

    • ID
    • Bus Address ID
    • Home Address ID

    Now for a form which edits or displays a Contact, being able to change the DisplayNameAttribute on the Address 'Street' property is not very helpful since I really want one field to be 'Business Street' and another to be 'Home Street'.

提交回复
热议问题