Edit data in entity framework database
I have created a database using entity framework CRUD.It allows editing from the index view only...But i want to edit data with a specific integer type id taken through a textbox..how can i do it??
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Joginder BangerRank #360 · 7K reputationPosted Feb 25, 2015, 9:42 PM EST
i hope this like might help you
http://www.dotnetcurry.com/showarticle.aspx?ID=619
Suraj SahooRank #382 · 6.6K reputationPosted Feb 25, 2015, 9:42 PM EST
Since you have used CRUD operation, then it edits/updates the record based on the primary key only.
If you want to have a separate edit page to update the record, then you need to have a separate action method for that.
You can also override the edit method. Like
public ActionResult EditRecord(EditModel model)
{
//AddOrUpdate();
//SaveChanges();
}
This will do the operation. You just need to have a Textbox where user will enter the id of the record and a button named Edit. Onclick of that Edit button retrieve the Id entered by the User and then send that to the Action method which will update the record based on the Id.
Remember to the action method you need to pass the whole model properties for the record along with the primary key/id. So that the record will be based on updated values.
You can use Ajax call here like:
var modelData = {
Property1:"",
Property2:"", //so on
};
then assign the properties the values, like
modelData.Property1 = $("#id").val(); //to assign the updated values.
$.ajax({
url:"/CONTROLLER/EDITMETHOD",
type:"POST",
data: modelData,
success: function(){
}
});
I hope this helps.
Accept if helps anyway.
Thanks