码迷,mamicode.com
首页 > 其他好文 > 详细

View Model转集合

时间:2016-05-29 18:32:48      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

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

View Model转集合

标签:

原文地址:http://www.cnblogs.com/yiran123456/p/5539933.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!