如何用字符ASP.NET替换字符串

时间:2016-03-05 00:16:30

标签: c# asp.net asp.net-mvc

有没有办法可以替换多个字符串,例如...热,冷,好,###?

文字字段

div class="form-group">
            @Html.LabelFor(model => model.Comment, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Comment, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Comment, "", new { @class = "text-danger" })
            </div>
        </div>
<div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Create" class="btn btn-default" />
        </div>
    </div>

控制器

     public ActionResult Create()
    {

        return View(new Charity());
    }

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "ID,DisplayName,Date,Amount,Comment")] Charity charity)
    {

        if (ModelState.IsValid)
        {
            db.Donations.Add(charity);
            db.SaveChanges();
            return RedirectToAction("Additionalinfo", "Charities");
        }
        return View(charity);
    }

模型

public class Charity
{
    public int ID { get; set; }
    [RegularExpression(@"^[a-zA-Z]+$", ErrorMessage = "Use letters only please")]
    public string DisplayName { get; set; }

    [DataType(DataType.Currency)]
    [Range(2, Int32.MaxValue, ErrorMessage = "Atleast £2.00 or a whole number please")]
    public int Amount { get; set; }
    public Double TaxBonus { get; set; }
    public String Comment { get; set; }
}

我可以用一个代码功能替换多个文本,还是必须单独为每个字符串?我是MVC和ASP.NET的新手,所以非常混乱。

1 个答案:

答案 0 :(得分:0)

所以你可以在你的控制器中做到这一点。

  CREATE TABLE Employee 
    (
         id        INT,         
         PRIMARY KEY (id)
    );

Create table ManagerRelation (
  id_from int NOT NULL,
  id_to int NOT NULL, 
  PRIMARY KEY (id_from, id_to),
  FOREIGN KEY (id_from) REFERENCES Employee(id),
  FOREIGN KEY (id_to) REFERENCES Employee(id)
);