1

我有一个基于字段值的视图,必须显示自定义标签。

视图模型:

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 回答