列挙型クラス
public enum DataReleaseChoice
{
Accept,
Decline,
[Display(Name = "Retrieve your application")]
Continue
}
私からしてみれば:
<input name="@Html.NameFor(model => model.DataReleaseAuthorization)" type="submit" value="@DataReleaseChoice.Accept" class="btn btn-primary" />
<input name="@Html.NameFor(model => model.DataReleaseAuthorization)" type="submit" value="@DataReleaseChoice.Decline" class="btn btn-primary" />
私がやろうとしているのは、新しい「続行」ボタンの行を追加することだけですが、DisplayAttributes 値 (「アプリケーションを取得します」) を表示する必要があります。
How to get the Display Name Attribute of an Enum member via MVC razor code?で提供されている例を見てきました。Razorビューで使用するのに苦労しています。次のコードを使用して、コントローラに値を表示できます。
var displayAttribute = PAI.Web.Utilities.EnumHelper<DataReleaseChoice>.GetDisplayValue(DataReleaseChoice.Continue);
しかし、次のようにカミソリビューで同じものを使用すると、
<input name="@Html.NameFor(model => model.DataReleaseAuthorization)" type="submit" value="@PAI.Web.Utilities.EnumHelper<DataReleaseChoice>.GetDisplayValue(DataReleaseChoice.Continue)" class="btn btn-primary" />,
エラーが発生します
Using the generic type 'EnumHelper<T>' requires 1 type arguments
私は MVC 5.2.3 を使用していますが、他のフォーラムで、MVC 5 が Enums の DisplayAttribute をすぐにサポートしていることを読みました。