2012-04-11 17 views
0

Ich habe eine Modellklasse, die 5 Eigenschaften enthält, aber nur 3 Eigenschaften werden in der Ansicht angezeigt. Wenn ich create action anrufe, muss ich nur diese 3 aktualisieren !!Update Teil des Modells

Ich versuche dies:

[HttpPost] 
public ActionResult Create([Bind(Exclude = "Id")]Location location) 
{ 
    if (ModelState.IsValid) 
     { 
      db.Location.Add(location); 

      bool car_in_database = db.Car.Any(c => c.Id == location.Car.Id); 
      if (car_in_database) 
      { 
       db.Entry(location.Car).State = EntityState.Modified; 
       db.Entry(location.Car).Property(l => l.ClientId).IsModified = false; 
      } 

      db.SaveChanges(); 

      return RedirectToAction("Index"); 
     } 

aber es funktioniert nicht .. Wer weiß, warum oder was ich zu tun habe?

Antwort

Verwandte Themen