Last active
April 6, 2016 19:33
-
-
Save rionmonster/4c2c644341b32ce9b15856bb63de851c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Complaint | |
{ | |
public int Id { get; set; } | |
public string Reason { get; set; } | |
public ComplaintFiler ComplaintFiler { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ActionResult Update(Complaint model) | |
{ | |
// Both the Reason and Id attributes should have been posted | |
// and will be present on the model | |
// So now you can actually update your model (for example purposes | |
// I'm doing this in the Controller, but you might have a more | |
// abstracted approach (e.g. a repository, etc.) | |
// Grab your entity | |
var original = _context.Complaints.Include(c => c.ComplaintFiler) | |
.FirstOrDefault(c => c.COMP_ID == model.Id); | |
if(original != null) | |
{ | |
// We found your original complaint, so update it | |
original.ComplaintReason = model.Reason; | |
// If you wanted to update a related entity or child property that was included, you could do that here | |
original.ComplaintFiler.Name = "Stupid complainer"; | |
// You would update other properties here as necessary | |
// After all of your changes were made, you would save them | |
SaveAll(); | |
return original; | |
} | |
// Your entity wasn't found, handle accordingly | |
return HttpNotFound(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model Complaint | |
<form action='@Url("Update","Home")'> | |
@Html.TextBoxFor(m => m.Reason) | |
@Html.HiddenFor(m => m.Id) | |
<input type='submit' value='Update!' /> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment