zoukankan      html  css  js  c++  java
  • 视图 Model转集合

    @{
        Layout = null;
    }
    @using MvcApplication2.Models

    <!DOCTYPE html>

    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Index</title>
    </head>
    <body>
        <div>
            <table>
                @foreach (var item in Model as List<Books>)
                {
                    <tr>
                        <td>@item.Title</td>
                        <td><a href="/Book/Delete/@item.Id">删除</a></td>
                    </tr>
                }
            </table>
        </div>
    </body>
    </html>

    public ActionResult Index()
            {
                List<Books> list=db.Books.Take(10).ToList();
                return View(list);
            }

    public ActionResult Delete(int id)
            {
                Books mod = (from b in db.Books where b.Id == id select b).FirstOrDefault();
                //Books mod=db.Books.Where(b => b.Id == id).FirstOrDefault();
                if (mod != null)
                {
                    db.Books.Remove(mod);
                    db.SaveChanges();
                    return Redirect("/Book/Index");
                }
                return Content("not found");
            }

  • 相关阅读:
    ntp时钟同步
    io,进程监控
    Linux下修改主机名
    DataGuard主库增加联机日志
    external table
    linux卸载HBA卡驱动
    Oracle DataGuard延迟应用归档归档日志
    index unusable
    VBOX 克隆虚拟机
    device eth0 has different MAC address than expected,igoring
  • 原文地址:https://www.cnblogs.com/yiran123456/p/5539933.html
Copyright © 2011-2022 走看看