You can try this solution for the RequiredIf attribute in MVC4 (or 3) in
http://cchitsiang.blogspot.com/2011/04/requiredif-conditional-validation-if.html
You can allow the user to submit an incomplete form or a fully validated form based on the check box. Be sure to change the following in RequiredIfAttribute.cs
[AttributeUsage (AttributeTargets.Property, AllowMultiple = true, Inherited = true)]
Regarding the link mentioned above,
For rollback lists to be checked, be sure to do the following in the model.cs file
Add boolean variable IsCompleted at the bottom of all variables
[Display(Name = "Completed")] public bool IsCompleted { get; set; }
for Dropdownlists to be checked pass DBsets to the ViewBag inside your controller, e.g.
ViewBag.Relationships = db.Relationships;
In the view, add dropdown menus as follows
@Html.DropDownListFor(model => model.RelationshipId, new SelectList(ViewBag.Relationships, "RelationshipId", "RelationshipName"), "--- Select ---") <br /> @Html.ValidationMessageFor(model => model.RelationshipId)
source share