asp.net mvc insert doesnt seem to work for me....

Posted by Pandiya Chendur on Stack Overflow See other posts from Stack Overflow or by Pandiya Chendur
Published on 2010-05-03T13:21:35Z Indexed on 2010/05/03 13:28 UTC
Read the original article Hit count: 369

Filed under:
|
|

My controller's call to repository insert method all the values are passed but it doesn't get inserted in my table..

My controller method,

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create([Bind(Exclude = "Id")]FormCollection collection)
        {
            try
            {
                MaterialsObj materialsObj = new MaterialsObj();
                materialsObj.Mat_Name = collection["Mat_Name"];
                materialsObj.Mes_Id = Convert.ToInt64(collection["MeasurementType"]);
                materialsObj.Mes_Name = collection["Mat_Type"];
                materialsObj.CreatedDate = System.DateTime.Now;
                materialsObj.CreatedBy = Convert.ToInt64(1);
                materialsObj.IsDeleted = Convert.ToInt64(1);
                consRepository.createMaterials(materialsObj);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

and my repository,

public MaterialsObj createMaterials(MaterialsObj materialsObj)
{
    Material mat = new Material();
    mat.Mat_Name = materialsObj.Mat_Name;
    mat.Mat_Type = materialsObj.Mes_Name;
    mat.MeasurementTypeId = materialsObj.Mes_Id;
    mat.Created_Date = materialsObj.CreatedDate;
    mat.Created_By = materialsObj.CreatedBy;
    mat.Is_Deleted = materialsObj.IsDeleted;
    db.Materials.InsertOnSubmit(mat);
    return materialsObj;
}

What am i missing here any suggestion....

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about insert