asp.net mvc insert doesnt seem to work for me....
- by Pandiya Chendur
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....