我想知道如何根据我提供的 Class_Id 移动到下一页,以显示类别中的产品。
比如Class_Id是1(即蔬菜)如果你按下action,我想显示Vegetables下的产品,如果是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 = (from d in db.ProductMasters where 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 参数,并在它们相等时显示数据
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句