Chapter 9: Creating Web Applications with ASP.NET MVC 275
new CustomerRepository()
.InsertCustomer(cust);
return RedirectToAction("Index");
}
catch
{
return View();
}
}
VB:
'
' GET: /Customer/Create
Function Create() As ActionResult
Dim cust As New Customer With
{
.Birthday = New DateTime(1980, 1, 1)
}
Return View(cust)
End Function
'
' POST: /Customer/Create
<HttpPost()> _
Function Create(ByVal cust As Customer) As ActionResult
Try
If String.IsNullOrEmpty(cust.Name) Then
ModelState.AddModelError(
"Name", "Name is required.")
End If
Dim custRep As New CustomerRepository
custRep.InsertCustomer(cust)
Return RedirectToAction("Index")
Catch
Return View()
End Try
End Function