Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir(s),

I am new in MVC,
I am updating customer data by passing only id, but not updating it.
How to update data?

Am i doing wrong?.Please suggest me if another way is available.

Thanks.

What I have tried:

C#
 [HttpPost, ActionName("Edit")]
 [ValidateAntiForgeryToken]
 public ActionResult Edit(int id)
 {
    Customers customers =   db.Customers.Find(id);
    if (TryUpdateModel(customers))  /* <- here debug point doesnt go inside*/
    {
           customers.Active = false;
           db.SaveChanges();
     }
}
Posted
Updated 27-Jun-18 7:38am
Comments
Richard Deeming 12-Jan-17 15:45pm    
If TryUpdateModel returns false, that means the values you've posted aren't valid.

To see the errors, debug your code and inspect the ModelState dictionary. Each value has an Errors collection which will tell you what the problem is.
Sunil Bansode 13-Jan-17 13:01pm    
Thanks for given idea.Its works for me.
Done it.
Karthik_Mahalingam 2-Feb-17 3:00am    
Always use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.

1 solution

You need to pass the variables that you need to save
for example
public ActionResult Edit(INVENTORY iis_inventory, string TYPE_CODE, string bc, bool as)
{

iis_inventory.invServiceType = TYPE_CODE;
....
...
db.SaveChanges();
}
 
Share this answer
 
Comments
Richard Deeming 27-Jun-18 13:47pm    
EIGHTEEN MONTHS late, and incorrect. TryUpdateModel works, as confirmed by the OP in the comments to the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900