Last post Feb 02, 2018 04:59 PM by datekk
Feb 02, 2018 04:18 PM|datekk|LINK
Hi. Sorry, I´m brand new in this stuff.
I have a SQL Database. The Table "Clients" is insert as Model in my MVC Application. This Table has alot of columns.
My goal is to have a view, where I can Edit ONLY one, three or two of thes columns of one Person.
This is actually a Part of my Controller:
// GET: Client/index/?id=1080
public ActionResult Index(int? id)
var sqlPerson = from c in db.Clients where c.ID == id select c.Id_Client, c.FirstName, c.LastName;
This, what is given to the View, should be just only one Record.
In the View I like to show the Data like:
An I also like to change the Data like @Html.EditorFor(m => Model.Lastname and a Submit Button.
First I tried it with var Person = db.Clients.Find(id); return View(sqlPerson); in the Controller. But after pushing the Submit Button, all Fields of the record, wich were not in a field in the view, were deleted.
My Post Controller is actuallly looking so:
public ActionResult Index(Kundenliste person)
db.Entry(person).State = System.Data.Entity.EntityState.Modified;
Can someone please help me to build it?
Feb 02, 2018 04:44 PM|ryanbesko|LINK
If the fields are part of the record and not submitted instead of blindly calling SaveChanges() you need to fetch the record you want to edit, update just the specific fields, mark the entity as modified, and then call SaveChanges(). See my answer to this
post about a date getting set to 1/1/0001 for this same reason, and an example of what I said you need to do.
Feb 02, 2018 04:59 PM|datekk|LINK
Thanks. That´s it. It works great!