Reputation: 37
I have these in my model class:
public string City { get; set; }
public string ZipCode { get; set; }
But I want to get it together as well. I tried doing something like this:
[DisplayFormat(City, Zipcode)]
public string CityZipCode { get; set; }
But that didn't work but maybe you get the idea of what I'm meaning. How can I get these together?
Please help me if you can, thanks!
Upvotes: 0
Views: 187
Reputation: 67195
You can create a property that generates what you want on the fly using the other properties. The advantage of this is that you don't actually need to store the combined string until you need it.
public string CityZipCode => $"{City}, {ZipCode}";
Upvotes: 3