I have a view where I need to detect if a property is decorated with hidden input.
My property is defined as:
[HiddenInput(DisplayValue = false)]
public string UserName{ get; set; }
My attempt so far has been:
var column.Member = "UserName";
if (ViewData.ModelMetadata.HideSurroundingHtml == true &&
ViewData.Values.Contains(column.Member))
{
column.Visible = false;
}
I have read that I might be able to use "HideSurroundingHtml" to determine if the property should not be displayed.
Any ideas how to detect this?
You can use reflection to see if a specific property has an attribute.
Look at this question.
In the various answers a user also posted a snippet to create an extension method to check if a property has a specific attribute or not. Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With