Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 如何从控制器在.NETMVC视图的html表中添加数据_Asp.net Mvc_Asp.net Mvc 4_Asp.net Mvc 3 - Fatal编程技术网

Asp.net mvc 如何从控制器在.NETMVC视图的html表中添加数据

Asp.net mvc 如何从控制器在.NETMVC视图的html表中添加数据,asp.net-mvc,asp.net-mvc-4,asp.net-mvc-3,Asp.net Mvc,Asp.net Mvc 4,Asp.net Mvc 3,我只想在我的表中动态添加两列。使用mvc razor。。下面是我的代码:- <table> <tr> <th>id</th> <th>name</th> <th>type</th> <th>delete</th> <th>modified</th> and for getting dat

只想在我的表中动态添加两列。使用mvc razor。。下面是我的代码:-

    <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>

身份证件
名称
类型
删除
被改进的
以及使用如下代码将数据获取到我的表m中:-
@foreach(Model.Rows中的System.Data.DataRow行)
{
@foreach(row.ItemArray中单元格中的变量)
{
如果(单元格!=null)
{
@cell.ToString()
}
否则{
}
}
}

现在我只想为每一行的delete和modified列添加一个链接。。感谢您的帮助

只需在内环后添加更多单元格即可:

<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>

@foreach(row.ItemArray中单元格中的变量){
如果(单元格!=null){
@cell.ToString()
}否则{
}
}
@*在行的末尾渲染某物*@

您可以在每个周期的单元格后的列中添加按钮。我还建议您使用PartialView来显示按钮,但这取决于您。下面是简单的方法。我还使用了一些引导类

  <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>

@foreach(Model.Rows中的System.Data.DataRow行)
{
@foreach(row.ItemArray中单元格中的变量)
{
如果(单元格!=null)
{
@cell.ToString()
}
否则{
}
}
}