【问题标题】:ASP.NET In mvc 6 ProjectASP.NET 在 mvc 6 项目中
【发布时间】:2018-07-30 20:18:57
【问题描述】:

我想知道如何根据我提供的 Class_Id 移动到下一页以显示类别中的产品。

例如Class_Id是1(即蔬菜)如果你按下action,我想显示蔬菜下的产品,如果是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>

【问题讨论】:

  • ..问题是?
  • 如何使用 class_Id 连接我的下一个表
  • -Timothy G. 请帮帮我兄弟?

标签: c# asp.net hyperlink


【解决方案1】:

var item = (来自 db.ProductMasters 中的 d 其中 d.Class_Id == id orderby 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 参数,如果它们相等则显示数据

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-16
    • 1970-01-01
    • 1970-01-01
    • 2017-02-19
    • 2016-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多