1

フィールド値に基づいて、カスタムラベルを表示する必要があるビューがあります。

ViewModel:

public class CreateAdViewModel
{
     public int Operation_Id { get; set; } 

     [Display(ResourceType = typeof(HeelpResources), Name = "AdViewModel_Price_Label")]
     public decimal Price { get; set; }
}

意見:

    <div id="price">
        @Html.DisplayNameFor(m => m.Price)
        @Html.TextBoxFor(m => m.Price) €
        @Html.ValidationMessageFor(m => m.Price)
    </div>

表示したい:

"Price: "  if Operation_Id = 1 (For the Sale of a Car)

"Price Up To: "  if Operation_Id = 2 (For someone looking for a car until value XX €)
4

1 に答える 1

0

2つのプロパティはどうですか:

public class CreateAdViewModel
{
    public int Operation_Id { get; set; }

    [Display(ResourceType = typeof(HelpResources), Name = "AdViewModel_Price_Label")]
    public decimal? Price { get; set; }

    [Display(ResourceType = typeof(HelpResources), Name = "AdViewModel_MaxPrice_Label")]
    public decimal? MaxPrice { get; set; }
}

ビュー内:

<div id="price">
    @if (Operation_Id == 1)
    {
        @Html.DisplayNameFor(m => m.Price)
        @Html.TextBoxFor(m => m.Price) €
        @Html.ValidationMessageFor(m => m.Price)
    }
    else
    {
        @Html.DisplayNameFor(m => m.MaxPrice)
        @Html.TextBoxFor(m => m.MaxPrice) €
        @Html.ValidationMessageFor(m => m.MaxPrice)
    }
</div>
于 2013-01-22T16:47:33.323 に答える