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");
            }

  • 相关阅读:
    缓存一致性问题
    缓存雪崩
    mysql Replication机制
    数据库水平切分、拆库拆表
    mysql分表和分区实际应用简介
    mysql中间件
    mysql基础知识
    go语言redis使用(redigo)
    nginx location配置与rewrite配置
    PDO驱动使用
  • 原文地址:https://www.cnblogs.com/yiran123456/p/5539933.html
Copyright © 2011-2022 走看看