|
Can't seem to figure how to do this or if it's possible. This module does not use ContentItems at all.
I have a model that contains instances of other models:
public class MetricRecord
{
[ScaffoldColumn(true)]
public virtual int Id { get; set; }
[Required]
[DisplayName("Metric Type")]
public virtual MetricTypeRecord MetricType { get; set; }
[DisplayName("Qualifier")]
public virtual QualifierRecord Qualifier { get; set; }
[DisplayName("Scorecard")]
public virtual ScorecardRecord Scorecard { get; set; }
[Required]
[DisplayName("Metric ID Name")]
public virtual string MetricIdName { get; set; }
}
So, MetricRecord contains a MetricTypeRecord, QualifierRecord, and ScorecardRecord
I'd like QualifierRecord and ScorecardRecord optional on the MetricRecord so that they can be null.
I can't seem to figure out how to configure my Controller to allow for null values for these though.
I'm passing in a FormCollection to my Action so I can do this, since the controls for selecting these items are dropdowns:
metric.MetricType = _metrictypeService.Get(int.Parse(collection["MetricType.Id"]));
This one works great because it's required and I don't have the option in the dropdown to not select an item.
For Scorecard and Qualifier, the first item in the dropdown is "Select an item" which passes a null value. I thought I could do this in the Controller:
if (collection["Scorecard.Id"] != null)
metric.Scorecard = _scorecardService.Get(int.Parse(collection["Scorecard.Id"]));
else
metric.Scorecard = null;
but it gives me an error. I can select something from the dropdown list and it updates fine.
Any ideas on how I configure the Controller to leave Scorecard and Qualifier null if an item is not selected?
Thanks so much for the assistance.
|