Reputation: 904
Am using a view with table (simple html tags) one like below to render in to two different views.
This table is inside MVC views>shared folder so does indicating its used by two different views.
View-1 needs all columns to display; But view-2 doesn't need column "Delete". How to conditionally render this shared (table-view) view showing only columns that the asking view needs?
<table id="example" class="display" style="min-width: 100%">
<thead>
<tr>
<th>Item</th>
<th>ItemDesc</th>
<th>UM</th>
<th>Qty</th>
<th>Category</th>
<th>Comment</th>
<th>Delete</th> /*View-2 don't need this*/
</tr>
</thead>
<tbody>
@foreach (var model in Model){
data goes here for respective <th> as <td> by getting from a model
<td>model.Item</td>
<td>model.ItemDesc</td>
<td>model.UM</td>
<td>model.Qty</td>
<td>model.Category</td>
<td>model.Comment</td>
<td>model.Delete</td> /*View-2 don't need this*/
}
</tbody>
How to do this in ASP MVC 5 views?
Upvotes: 0
Views: 75
Reputation: 18883
You can just store a token value inside Viewbag or Tempdata as :
@Viewbag.show="no";
if(@Viewbag.show!="no"){
<td>model.Delete</td>
}
else{
<td></td>
}
Upvotes: 1
Reputation: 4550
One of the solution is pass the additional information in the modal of the view like this
if(modal.EnableDelete)
<td>Delete</td>
Upvotes: 1