I've been looking around stackoverflow for this answer. Can't seem to get anywhere with them. I have an entity which has 5 navigation properties to other entities. Example:
public class Computer : DbEntity
{
public virtual Ram Ram { get; set; }
public Guid RamId { get; set; }
public virtual Hdd Hdd { get; set; }
public Guid HddId { get; set; }
// etc. etc. you get the picture
}
In order to build the View up, I made partial Create views for Hdd and Ram etc. and referenced them into the main view:
@model ComputerSite.ViewModels.ComputerViewModel
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Computer Details</legend>
... some fields ...
</fieldset>
Html.RenderPartial("Create", "Ram");
Html.RenderPartial("Create", "Hdd");
}
And I tested this and it works, all the data gets posted back to the ViewModel and it can be saved in the database, so I know all of that works. The problem comes when, a Computer has no Ram. I want to be able to check a box to say this won't be included. And when the form is submitted to bypass the Ram validation.
There should be a very easy and simple way, I don't mind if it is a JavaScript function that goes and changes some data- attributes client side. I'm just not entirely sure where to start, custom attributes aren't the way forward with this. It seems way to much just to change some fields. I still want the fields validated if the check box isn't checked and the validation is in place for that, and that bit works, hence why I'm asking the question, I just need to be able to selectively turn off different parts of the form.
Oh, and as a side note, NON of my properties in any of my entity classes have the [Required] attribute!
Examples please if you do JavaScript. I'm 100% proficient with it yet.