In my controller “Language” I have the following Create action method
<HttpPost()>
Function Create(language As Language) As ActionResult
Try
If ModelState.IsValid Then
Dim name As String = language.Name
db.Languages.Add(language)
db.SaveChanges()
Return RedirectToAction("Index", New System.Web.Routing.RouteValueDictionary(New With {.languageName = name, .onSuccess = ActionType.CREATE}))
End If
Catch ex As DataException
ViewBag.ErrorTitle = Resources.Commands.UnableToCreate
ViewBag.ErrorMessage = Resources.Commands.TryAgainMessage
End Try
Return View(language)
End Function
How can I check if exists duplicates with the same values in the database before creating?
forgive me, my VB is very rusty
Or implement
IValidatableObjectin your model that performs the check (probably a better approach):Link on MVC3 model validation: http://www.devproconnections.com/article/aspnetmvc/modellevel-validation-aspnet-mvc-3-136111