2017-11-25 3 views
1

i 테이블에 동적으로 두 개의 열을 추가하고 싶습니다. MVC 면도기를 사용하여 .. 이것은 아래에있는 내 코드입니다 : -mvc .net에서 동적으로 열을 추가하십시오.

<table> 
    <tr> 
    <th>id</th> 
    <th>name</th> 
    <th>type</th> 
    <th>delete</th> 
    <th>modified</th> 


    and for getting data to my table m using code like :- 

    <tbody> 
    @foreach (System.Data.DataRow row in Model.Rows) 
    { 
    <tr> 
    @foreach (var in cell in row.ItemArray) 
    { 
    if (cell ! = null) 
    { 
     <td>@cell.ToString()</td> 
    } 
    else { 
     <td></td> 
    } 
    } 
</tr> 
} 
<tbody> 
</table> 

지금 난 그냥 도움

답변

0

에 대한 .. 각 행에 대한 삭제 및 수정 열 모두에 감사를 하나 개의 링크를 추가 할 내부 루프 다음에 더 많은 셀을 추가하기 만하면됩니다.

<tr> 
    @foreach (var in cell in row.ItemArray) { 
    if (cell ! = null) { 
    <td>@cell.ToString()</td> 
    } else { 
    <td></td> 
    } 
    } 
    <td>@* Render something at the end of the row*@</td> 
</tr> 
1

셀이 foreach 사이클 한 후에 열에 버튼을 추가 할 수 있습니다. 나 또한 당신이 버튼 디스플레이에 대한 PartialView를 사용 sugest하지만 이것은 당신에 따라 다릅니다. 아래는 간단한 방법입니다. 또한 부트 스트랩 클래스를 사용했습니다.

<tbody> 
     @foreach (System.Data.DataRow row in Model.Rows) 
     { 
     <tr> 
     @foreach (var in cell in row.ItemArray) 
     { 
     if (cell ! = null) 
     { 
      <td>@cell.ToString()</td> 
     } 
     else { 
      <td></td> 
     } 
     } 
    <td> 

<a class="btn btn-primary btn-sm" href="@Url.Action("Edit", "ABC", new { id=Model.Id})" title="Edit ABC"><i class="glyphicon glyphicon-edit"></i></a></td> 
<td> 
<a class="btn btn-info btn-sm" href="@Url.Action("Details", "ABC", new { id=Model.Id })" title="Details of ABC"><i class="glyphicon glyphicon-file"></i></a></td> 
<td> 
<a class="btn btn-danger btn-sm" href="@Url.Action("Delete", "ABC", new { id=Model.Id })" title="Delete this ABC"><i class="glyphicon glyphicon-remove"></i></a></td> 
</tr> 
} 
</tbody> 
관련 문제