【问题标题】:Display List Of files in grid using .net mvc razor c#使用.net mvc razor c#在网格中显示文件列表
【发布时间】:2016-04-05 05:51:20
【问题描述】:

我的控制器代码

public ActionResult Index()
    {
      DirectoryInfo dirInfo = new DirectoryInfo(@"C:\Users\Documents\New folder");
      List<FileInfo> files = dirInfo.GetFiles("*.pdf").ToList();
      return View(files);
    }

我的 ViewCode 是

@model IEnumerable<FileInfo>

@{
    ViewBag.Title = "Home Page";
 }

@foreach (FileInfo file in Model)
{
  <li>@file.Name</li>
  <li>@file.Extension</li>
}

这里我需要在网格中显示这些文件列表及其超链接作为图像。

提前感谢任何建议..

【问题讨论】:

    标签: c# asp.net asp.net-mvc-4 razor


    【解决方案1】:

    您可以使用下面的代码,但我建议使用任何 jquery 库作为网格,如 jqgrid..

    <table class="grid">
        <tr>
            <th>Name</th>
            <th>Extension</th>
            <th>Edit</th>
        </tr>
        @foreach (var item in Model)
        { 
    
            <tr>
                <td class="left">@item.Name</td>
                <td class="left">@item.Extension</td>
                <td>
                    <a href="@Url.Action("Edit", new { id = item.ID })">
                        <img src="@Url.Content("~/Content/Images/Image.bmp")", alt="Edit" /></a>
                </td>
            </tr>   
        }
    </table>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-20
      • 2018-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多