繁体   English   中英

ASP.NET在MVC 6项目中

[英]ASP.NET In mvc 6 Project

我想知道如何根据我给在类别中显示产品的Class_Id转到下一页。

例如,如果按操作,如果Class_Id为1(例如,对于蔬菜),则我想在“蔬菜”下显示产品(如果为2),则需要显示下一个类别,依此类推。

这是我的控制器:

public class CategoryController : Controller
    {      

        // GET: Category
        private DBEntities db = new DBEntities();

        //TO Display the Page
        public ActionResult ShowProduct()
        {
            DBEntities db = new DBEntities();
            var item = (from d in db.Category_Master
                        select d).ToList();
            return View(item);
        }

        //To Display the Exisiting Catrgories
        public ActionResult List(int id = 0)
        {
            return View(db.Category_Master.ToList());
        }
        //To Edit 
        public ActionResult Edit(int id = 0)
        {
            return View(db.Category_Master.Find(id));
        }
        [HttpPost, ValidateAntiForgeryToken]
        public ActionResult Edit(Category_Master mm, HttpPostedFileBase image2)
        {
            var db = new DBEntities();
            if (image2 != null)
            {
                mm.Category_IMG = new byte[image2.ContentLength];
                image2.InputStream.Read(mm.Category_IMG, 0, image2.ContentLength);

            }
            db.Entry(mm).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("List");
        }
        //To Add New

        public ActionResult New()
        {
            Category_Master b1 = new Category_Master();
            return View(b1);
        }
        [HttpPost]
        public ActionResult New(Category_Master model, HttpPostedFileBase image1)
        {
            var db = new DBEntities();
            if (image1 != null)
            {
                model.Category_IMG = new byte[image1.ContentLength];
                image1.InputStream.Read(model.Category_IMG, 0, image1.ContentLength);

            }
            db.Category_Master.Add(model);
            db.SaveChanges();
            return View(model);
        }
        //To Delete

        public ActionResult Delete(int id = 0)
        {
            return View(db.Category_Master.Find(id));
        }
        [HttpPost, ActionName("Delete")]
        public ActionResult Delete_conf(int id)
        {
            Category_Master CM = db.Category_Master.Find(id);
            db.Category_Master.Remove(CM);
            db.SaveChanges();
            return RedirectToAction("List");
        }

//my Category Model

    public partial class Category_Master
    {
        [Key]
        public int Class_Code { get; set; }
        public int Class_Id { get; set; }
        public string Category_NM { get; set; }
        public string vMode { get; set; }
        public byte[] Category_IMG { get; set; }

    }


//My View For That Controller
<div style="margin-left:40px;">
    @if (Model != null)
    {
        <ul>
            @foreach (var item in Model)
            {
                <li style="color:crimson">
                    Product name:@item.Category_NM
                    <br />
                    @{
                        var base64 = Convert.ToBase64String(item.Category_IMG);
                        var imgsrc = string.Format("data:image/gif;base64,{0}", base64);
                    }<div class="img-rounded dropdown">
                        <img src='@imgsrc' style="max-width:100px;max-height:100px" />
                        <br />
                    </div>
                    <a href="/Product/Commodity" style="color:black">Click to buy</a>
                </li>
            }
        </ul>
    }
 </div>

var item =(从db.ProductMasters中的d获得,其中d.Class_Id == id由d.Sequence_No排序

                    where d.IsActive != false 
                    join f in db.PriceMasters on d.Product_Id equals f.Product_Id
                    select new USP_Class_Product_Result {ProductName=d.ProductName,ProductImage=d.ProductImage,Price=f.Price }).ToList();
        return View(item);

USP_Class_Product_Result是存储过程。 它获取在两个表中都通用的Class_id参数,并在它们相等时显示数据

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM