I have the following in my view:
@Html.HiddenFor(x => x.MeasurementUnitType)
MeasurementUnitType is an enum which looks like:
public enum MeasurementUnitType
{
Metric, Imperial
}
Whatever happens to that enum on the model, the hidden field is always set to metric.
I did try having an editor template for it:
@using Ns.Domain.Models.Enums
@model Ns.Domain.Models.Enums.MeasurementUnitType
@{
switch (Model)
{
case MeasurementUnitType.Metric:
<text>
@Html.Hidden("Metric", ViewData.TemplateInfo.FormattedModelValue)
</text>
break;
case MeasurementUnitType.Imperial:
<text>
@Html.Hidden("Imperial", ViewData.TemplateInfo.FormattedModelValue)
</text>
break;
default:
throw new ArgumentOutOfRangeException();
}
}
but that would output the hidden field as
<input id="NewTable_MeasurementUnitType_Metric" name="NewTable.MeasurementUnitType.Metric" type="hidden" value="Metric" />
or
<input id="NewTable_MeasurementUnitType_Imperial" name="NewTable.MeasurementUnitType.Metric" type="hidden" value="Imperial" />
respectively
this wont work as the Id has the actual value of the enum as well as the name of the enum in the Id...
Anyone got any ideas?