Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect in code if property is decorated with HiddenInput

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?

like image 641
cpoDesign Avatar asked Nov 05 '22 02:11

cpoDesign


1 Answers

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

like image 91
Iridio Avatar answered Nov 15 '22 13:11

Iridio