Fe+mvc sub-page

Source: Internet
Author: User
Tags actionlink

  publicActionResult Create () {returnView (); } [httppost] publicactionresult Create (Books book) {book. CreateDate=datetime.now;            DBCONTEXT.BOOK.ADD (book); varres =dbcontext.savechanges (); if(res >0)            {                //return Content ("add success");                returnRedirecttoaction ("Index"); }            Else            {                returnContent ("New Failure"); }        }         publicActionResult Edit (intId) {varBook =DbContext.Book.Find (id); returnView (book); } [httppost] publicactionresult Edit (Books book) {dbcontext.entry<Books> (book). State =System.Data.Entity.EntityState.Modified; varres =dbcontext.savechanges (); if(res >0)            {                returnRedirecttoaction ("Index"); }            Else                returnContent ("modification failed! "); }        //[httppost]//public actionresult Edit (Books book)//{        //dbcontext.entry<books> (book).        State = System.Data.Entity.EntityState.Modified; //var res = dbcontext.savechanges (); //if (res > 0)//    {        //return redirecttoaction ("Index"); //    }        //Else//    {        //return Content ("modification failed"); //    }        //}         publicActionResult Delete (intId) {//gets the ID of the objectBooks book =NewBooks {Id =id}; Dbcontext.entry<Books> (book). State =System.Data.Entity.EntityState.Deleted; varres =dbcontext.savechanges (); if(res >0)            {                returnRedirecttoaction ("Index"); }            Else                returnContent ("Delete Failed"); }

namespace mscampus.mvc.models{[Table ("bookinfos")] public class Books {        [Key]        [Display (Name = "number")] public int Id {get; set;}        [Display (name = "names")]        [Column ("bookname")] public string Name {get; set;}        [Display (Name = "price")] public decimal Prices {get; set;}        [Display (Name = "category")] public string category {get; set;}    [Display (Name = "creation time")] public DateTime createdate {get; set;} }}
Declares the EF database context        private Mscampusdatamodel dbContext = new Mscampusdatamodel ();        Get:book public        actionresult Index (string txtname, int pageIndex = 1)        {            //ef page            const int pageSize = 5;            ipagedlist<books> Listbook = null;            If (!string. IsNullOrEmpty (txtname))            {                listbook = dbContext.Book.OrderByDescending (n = N.id)                    . Where (n = n.name.contains (txtname))                    . Topagedlist (pageIndex, pageSize);            }            else            {                Listbook = dbContext.Book.OrderByDescending (n = N.id)                    . Topagedlist (pageIndex, pageSize);            }            Viewbag.querytitle = txtname;            return View (listbook);            var list = dbcontext.book;            return View (list);        }

  

@model ienumerable<mscampus.mvc.models.books> @using x.pagedlist@using x.pagedlist.mvc@{ViewBag.Title = "Index ";} 

  

  

Fe+mvc sub-page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.