视图cshtml页面顶部设置
1、@model Model.Product
2、在相应内容地方显示数据,例如:
商品标题:<h1>@Html.DisplayFor(model => model.title)</h1>
商品图片:<img src='@Html.DisplayFor(model => model.images)' width=500 />
控制器:productController.cs
public ActionResult show(int id)
{
Model.Products model = new Model.Products();
model.id = (int)ds.Tables[0].Rows[0]["id"];
model.images = ds.Tables[0].Rows[0]["images"].ToString();
model.price = decimal.Parse(ds.Tables[0].Rows[0]["price"].ToString());
model.title = ds.Tables[0].Rows[0]["title"].ToString();
...省略其他字段
return View(model);
}
模型model
namespace Model
{
public partial class Products
{
public int id { get; set; }
public string title { get; set; }
public string keys { get; set; }
public string nums { get; set; }
public int classid { get; set; }
public int selltype { get; set; }
public string images { get; set; }
public decimal price { get; set; }
public decimal pricebase { get; set; }
public decimal priceshop { get; set; }
public decimal pricein { get; set; }
public string attrs { get; set; }
public string expends { get; set; }
public int sellcount { get; set; }
public int hitcount { get; set; }
public int store { get; set; }
public string tags { get; set; }
public int isnew { get; set; }
public int ishot { get; set; }
public int sortid { get; set; }
public int status { get; set; }
public string contents { get; set; }
public int shopid { get; set; }
public int userid { get; set; }
public string times { get; set; }
}
}
数据库部分使用ODBC,微软SqlHelper,习惯了。
开始也用了EF,用不习惯