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

  • 相关阅读:
    Apache、NGINX支持中文URL
    JS中关于clientWidth offsetWidth scrollWidth 等的含义
    设置apache登陆密码验证
    通过java代码访问远程主机
    win7
    Netty从没听过到入门 -- 服务器端详解
    分块分段
    数论-佩尔方程
    数论-毕达哥拉斯三元组
    HDU 5613-Baby Ming and Binary image
  • 原文地址:https://www.cnblogs.com/yiran123456/p/5539933.html
Copyright © 2011-2022 走看看