【问题标题】:Add Tax to user input in Razor在 Razor 中向用户输入添加税
【发布时间】:2018-03-11 13:03:39
【问题描述】:

如何在 Razorview 中为用户输入添加税值

这是当前代码

<div class="form-group">
    @Html.LabelFor(model => model.Price, htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @{
            double tax = 12.5;
        }

        @Html.EditorFor(model => model.Price * tax, new { htmlAttributes = new { @class = "form-control" } })
        @Html.ValidationMessageFor(model => model.Price, "", new { @class = "text-danger" })

    </div>
</div>

这不起作用,请帮助我

【问题讨论】:

  • 实际上,当我运行此代码时,应用程序崩溃了 - 所以如果我在代码中输入错误,我需要帮助。

标签: c# asp.net html razor


【解决方案1】:

我会在我的模型中创建一个属性,返回包含税的价格。

public class model
{
    public decimal Price { get; set; }
    public decimal PriceWithTax
    {
        get
        {
            return Price * 1.125m;
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-27
    • 1970-01-01
    • 1970-01-01
    • 2020-08-22
    • 2012-06-08
    • 1970-01-01
    • 2012-06-14
    相关资源
    最近更新 更多