hypercixxx12
New Member
I am developing a client-side and server-side validation for a certain viewModel property.In the .cshtml file I put this:\[code\]@Html.DropDownListFor(model => model.EntityType.ParentId, Model.ParentTypeList, "")@Html.ValidationMessageFor(model => model.EntityType.ParentId)\[/code\]In the Controller for the business validation\[code\]catch (BusinessException e){ ModelState.AddModelError("EntityType.ParentId", Messages.CircularReference);}\[/code\]This way it works as expected. If an exception is caught, the message appears next to the dropdownlist.However I find that this way is not very elegant. In the cshtml I use a method to generate all the required information about the validation. In the controller I must know the exacty Key string and use it.Ins't there a better way of doing this? Thank you.