我的产品表的ID不是从1开始

时间:2019-04-02 16:25:29

标签: c# asp.net-mvc

每当我保存产品数据时,产品ID均以1006等开头,但不以1开头。 而且我的表格在状态列中未保存任何内容

这是我桌子的图片 ProductID以1006开头 enter image description here

这是我添加产品的控制器代码

[HttpPost]
        public ActionResult ProductsView(product model)
        {

            product tbl = new product();
            string fileName = Path.GetFileNameWithoutExtension(model.ImageFile.FileName);
            string extension = Path.GetExtension(model.ImageFile.FileName);
            fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;

            tbl.ProductName = model.ProductName;
            tbl.ProductDescription = model.ProductDescription;
            tbl.Price = model.Price;
            tbl.Quantity = model.Quantity;
            tbl.CategoryName = model.CategoryName;
            tbl.Status = model.Status;

            tbl.Image = "~/Image/" + fileName;
            fileName = Path.Combine(Server.MapPath("~/Image/"), fileName);
            model.ImageFile.SaveAs(fileName);
            db.products.Add(tbl);
            db.SaveChanges();
            return View();
        }

这是我的产品型号

 public partial class product
    {
        public int ProductID { get; set; }
        public string ProductName { get; set; }
        public string ProductDescription { get; set; }
        public Nullable<decimal> Price { get; set; }
        public Nullable<int> Quantity { get; set; }
        public string CategoryName { get; set; }
        public Nullable<int> CategoryID { get; set; }
        [DisplayName("Upload Image")]
        public string Image { get; set; }
        public HttpPostedFileBase ImageFile { get; set; }

        public string Status { get; set; }

        public virtual category category { get; set; }
    }

这是我的观点

@model myadminpanel.Models.product

@using (Html.BeginForm("ProductsView","Product",FormMethod.Post,new { enctype="multipart/form-data"}))
{

<div class="container">

    <div class="form-group">
        <label>Item Name</label>

        <input class="form-control" name="ProductName" placeholder="Enter Product Name" />


    </div>
    <div class="form-group">
        <label>Item Description</label>

        <input class="form-control" name="ProductDescription" placeholder="Enter Item Description" />


    </div>
    <div class="form-group">
        <label>Item Price</label>

        <input class="form-control" name="Price" placeholder="Enter Item Price" />


    </div>
    <div class="form-group">
        <label>Item Quantity</label>

        <input class="form-control" name="Quantity" placeholder="Enter Item Quantity" />


    </div>
    <div class="form-group">
        <label>Category Name</label>

        <input class="form-control" name="CategoryName" placeholder="Select Category Name" />


    </div>


    <div class="form-group">
        <label>Satus(Available/Not Available)</label>

        <input class="form-control" name="Satus" placeholder="Enter Satus As Available/Not Available" />


    </div>
    <div class="form-group">
        <label>Item Image</label>

        <input type="file" name="ImageFile" required />



    </div>
    <div class="button">
        <button>Submit</button>

    </div>
    <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav">
            <li>@Html.ActionLink("Show/Edit/Delete", "ProductShow", "Product")</li>
        </ul>
    </div>

</div>
}

0 个答案:

没有答案