Hello Team,
This is the error I am getting from my code, kindly assist, Employee.Models.tblStaff does not contain a defination for PicturePath and no extension method 'PicturePath' accepting a first argument of type.
Hello Team,
This is the error I am getting from my code, kindly assist, Employee.Models.tblStaff does not contain a defination for PicturePath and no extension method 'PicturePath' accepting a first argument of type.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Naimish MakwanaPosted Apr 2, 2024, 4:32 AM
The error message you’re seeing is indicating that the
tblStaffclass does not have a property namedPicturePath. In yourSaveStaffmethod, you’re trying to assign a value tosaveStaff.PicturePath, which is causing the error.Your
StaffViewModelclass does have aPicturePathproperty, but it seems like this property is not present in yourtblStaffclass. To resolve this issue, you need to add aPicturePathproperty to yourtblStaffclass. Here’s how you can do it:After adding this property, Entity Framework should create a corresponding column in your
tblStaffstable in the database (assuming you’re using Code First). Then, you should be able to assign a value tosaveStaff.PicturePathin yourSaveStaffmethod without getting an error.Thanks
Emmmanuel FIADUFEPosted Apr 2, 2024, 4:55 PM
Thank you team,
I did the changes and the error message is no longer showing but when I tried saving data, i got a different error message pop up saying validation failed for one or more entities.
Jayraj ChhayaPosted Apr 2, 2024, 6:14 AM
Problem
The error message you mentioned indicates that the
tblStaffmodel does not have a definition for the propertyPicturePath. This means that thePicturePathproperty is missing in thetblStaffmodel, causing the error when trying to assign a value to it.Cause
The cause of the error is that the
tblStaffmodel does not have aPicturePathproperty defined. This could be due to a missing or incorrect definition in the model class.Solution
To fix the error, you need to add the
PicturePathproperty to thetblStaffmodel class. Open thetblStaffmodel class and add the following property:Emmmanuel FIADUFEPosted Apr 1, 2024, 11:18 AM
This is the full code.
public ActionResult SaveStaff(StaffViewModel staffmodel)();
{
if (staffmodel.StaffId > 0)
{
tblStaff updateStaff = objRestaurantDBEntities.tblStaffs.Where(a => a.StaffId == staffmodel.StaffId).FirstOrDefault
updateStaff.JoinDate = staffmodel.JoinDate;
updateStaff.FName = staffmodel.FName;
updateStaff.LName = staffmodel.LName;
updateStaff.BirthDate = staffmodel.BirthDate;
updateStaff.Phoneno = staffmodel.Phoneno;
updateStaff.Email = staffmodel.Email;
updateStaff.NextofKing = staffmodel.NextofKing;
updateStaff.Phone = staffmodel.Phone;
objRestaurantDBEntities.SaveChanges();
updateStaff.StaffId = staffmodel.StaffId;
return Json(new { result = true, message = "Staff info updated successfully....!" }, JsonRequestBehavior.AllowGet);
}
else
{
tblStaff saveStaff = new tblStaff();
saveStaff.PicturePath = (!string.IsNullOrEmpty(staffmodel.PicturePath)) ? staffmodel.PicturePath : saveStaff.PicturePath;
saveStaff.JoinDate = staffmodel.JoinDate;
saveStaff.FName = staffmodel.FName;
saveStaff.LName = staffmodel.LName;
saveStaff.BirthDate = staffmodel.BirthDate;
saveStaff.Phoneno = staffmodel.Phoneno;
saveStaff.Email = staffmodel.Email;
saveStaff.NextofKing = staffmodel.NextofKing;
saveStaff.Phone = staffmodel.Phone;
objRestaurantDBEntities.tblStaffs.Add(saveStaff);
objRestaurantDBEntities.SaveChanges();
}
return Json(new { result = true, message = "Staff info updated successfully....!" }, JsonRequestBehavior.AllowGet);
}
ModelView
public class StaffViewModel
{
public string JoinDate { get; set; }
public string FName { get; set; }
public string LName { get; set; }
public HttpPostedFileBase StaffImage { get; set; }
public string PicturePath { get; set; }
}