Please enable JavaScript.
Coggle requires JavaScript to display documents.
BUILDING-FORMS - Coggle Diagram
BUILDING-FORMS
SAVE-UPDATE
Decorate
SaveAction
[HttpPost]
IfNot-CustomerId
.Add(customer)
_context
.SaveChanges()
Transaction
Wrapped
RedirectToAction(..)
"Index"
"Customers"
Else
customerInDb
_context.Customers
.Single(c => c.Id == customer.Id)
customerInDb.Field =
customer.Field
In-Form
Add
HiddenField
For-Id
@Html.HiddenForm(..)
m => m.Customer.Id
ERRORS
Troubleshoot
DbEntityValidationException
DebugMode
Inspect
e
Wrap
Try{}-Catch(<Error> e){...}
Console.WriteLine(e)
DROP-DOWN
@Html.DropDownListFor(...)
m => m.Customer.MemTypeId
new SelectList(...)
Model.MemTypes
"Id"
"Name"
new { @class = "form-control" }
EDIT
Args
int id
var customer
_context.Customers.SingleOrDefault(..)
c => c.Id == id
If-CustomerNull
Return
HttpNotFound()
Else
viewModel
customer
memTypes
Return
View(..)
CustomerForm
viewModel
MARKUP
Render
@using (..) { htmlCode }
Html.BeginForm(action, controller)
@Html
.LabelFor(m => m.Name)
.TextBoxFor(...)
m => m.Name
new { @class = "form-control" }
["{0:d MMM yyyy}"]
FORM-LABELS
DataAnnotation
In-ModelClass
[Display(Name = "...")]
Recompiled
EveryTime
RawHtml
<label for="..."></label>
Required
for-attr
ModelPropChange
Not
AutoUpdated
MODEL-BINDING
AutoBinded
RequestData
ModelParam
Save(Customer customer)
Keys
In-FormData
Prefixed
Customer
NEW
viewModel
memTypes =
_context.MemTypes
.ToList()
Return
View(..)
CustomerForm
viewModel