public class MyViewModel
{
public bool BeVisiable { get; set; }
public List<MyModel> Vdata { get; set; }
}
public class MyModel
{
public string adminstring { get; set; }
}
Test Result
No data
With data
With Regards,
Fei Han
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
The extra column is just a mistake trying to show you how my table structure looks like. The structure is like this
I do not understand your response. The example table has 2 columns similar to your table. Maybe you want to show hide the second column? Can you clearly explain the problem you are trying to solve and/or why the forum member suggestion are not meeting
your expectations?
Thanks for your response. The example table has 2 columns similar to your table. Maybe you want to show hide the second column? Yes correct. I will try your solution and update you tomorrow
Member
50 Points
192 Posts
Hide html <thead> <th>
Dec 05, 2019 01:16 AM|denkyira|LINK
I want to hide an html header th when the body td item is null. Below is portion of my code
<thead><tr> <th id="hide">ID</th></tr> </thead>-----> Hide this
<tbody><tr><td id="hideheader">@item.adminstring</td></tr></tbody>-----when the value of adminstring is null
Contributor
2096 Points
1040 Posts
Re: Hide html <thead> <th>
Dec 05, 2019 03:04 AM|Khuram.Shahzad|LINK
Contributor
2096 Points
1040 Posts
Re: Hide html <thead> <th>
Dec 05, 2019 03:11 AM|Khuram.Shahzad|LINK
All-Star
40565 Points
6233 Posts
Microsoft
Re: Hide html <thead> <th>
Dec 05, 2019 05:36 AM|Fei Han - MSFT|LINK
Hi denkyira,
To achieve the above requirement, you can refer to the following approach.
<table> <thead><tr class="@(Model.BeVisiable? "visible-row" : "hidden-row")"> <th id="hide">ID</th></tr> </thead> @foreach (var item in Model.Vdata) { <tbody><tr><td id="hideheader">@item.adminstring</td></tr></tbody> } </table>
In controller action
public class MyViewModel { public bool BeVisiable { get; set; } public List<MyModel> Vdata { get; set; } } public class MyModel { public string adminstring { get; set; } }
Test Result
No data
With data
With Regards,
Fei Han
Member
50 Points
192 Posts
Re: Hide html <thead> <th>
Dec 05, 2019 06:05 PM|denkyira|LINK
Good Day Khuram
Thanks for your response. So unfortunately none of the solutions suggested here works for me.
All-Star
53021 Points
23601 Posts
Re: Hide html <thead> <th>
Dec 05, 2019 06:27 PM|mgebhard|LINK
I think part of the confusion is your requirement only makes sense of the table has one row.
Member
50 Points
192 Posts
Re: Hide html <thead> <th>
Dec 05, 2019 07:30 PM|denkyira|LINK
Hi
Thanks for your response. Actually this is how my table structure looks like
All-Star
53021 Points
23601 Posts
Re: Hide html <thead> <th>
Dec 05, 2019 07:39 PM|mgebhard|LINK
The table HTML is invalid. There are 2 table headers and 3 columns with and extra <td>.
Other than the invalid HTML, do you have a question or problem?
Member
50 Points
192 Posts
Re: Hide html <thead> <th>
Dec 05, 2019 08:14 PM|denkyira|LINK
The extra column is just a mistake trying to show you how my table structure looks like. The structure is like this
All-Star
53021 Points
23601 Posts
Re: Hide html <thead> <th>
Dec 05, 2019 08:44 PM|mgebhard|LINK
I do not understand your response. The example table has 2 columns similar to your table. Maybe you want to show hide the second column? Can you clearly explain the problem you are trying to solve and/or why the forum member suggestion are not meeting your expectations?
Still, your requirement does not make sense if the table contains more than one row.
Member
50 Points
192 Posts
Re: Hide html <thead> <th>
Dec 05, 2019 08:49 PM|denkyira|LINK
Thanks for your response. The example table has 2 columns similar to your table. Maybe you want to show hide the second column? Yes correct. I will try your solution and update you tomorrow
Contributor
2096 Points
1040 Posts
Re: Hide html <thead> <th>
Dec 06, 2019 02:57 AM|Khuram.Shahzad|LINK
Member
50 Points
192 Posts
Re: Hide html <thead> <th>
Dec 06, 2019 03:42 PM|denkyira|LINK
Hi
Thanks a lot. Your solution save my life.