views:

288

answers:

2

If I have a property whose display format is dependent on the value of another property in the view model how do I create a display template for it?

The combination of field1's display being dependent on field2's value will be used throughout the app and I would like to encapsulate this in a MVC 2 display template.

To be more specific, I've already create a display template (Social.ascx) for custom data type Social that masks a social security number for display. For instance, XXX-XX-1234.

[DataType("Social")]
public string SocialSecurityNumber { get; set; }

All employees also have an employeeID. Certain companies use the employee's social security number as either the whole employee id or as part of it. I need to also mask the employeeID if it contains the social. I'd like to create another display template (EmpID.ascx) to perform this task.

[DataType("EmpID")]
public string EmployeeID { get; set; }

The problem is that I don't know how to get both properties in the "EmpID" template to be able to perform the comparison.

Thanks for the help.

A: 

This might not directly answer your question but I'm wondering why the Employee ID is only sometimes marked out. I know there are legal requirements to doing so for the social but the employee ID is (or should be) somewhat sensitive as well. I would think it would be better to default to marking out both unless the logged in user had whatever privileges made them fully readable.

If you can do this that would probably simplify your logic/design somewhat.

confusedGeek
A: 

Cant you create a custom ViewModel class containg both SocialSecurityNumber and EmployeeID and create a custom editor template for that class?

Kenny Eliasson