Unmapped字段所需的消息?

时间:2013-08-19 06:38:14

标签: asp.net-mvc-3

我在asp.net MVC3中有一个未映射的字段。我想显示此字段所需的消息,但我不能。如何为未映射的字段显示所需的消息?可能吗 ?

 [Required(ErrorMessage = "Email alanı girilmelidir.")]
        public string FirstEMail
        {
            get
            {
                return first_email;
            }
            set
            {
                first_email = value;
            }
        }

DAL:

modelBuilder.Entity<AbsKontak>().Ignore(p => p.FirstEMail);

查看:

Html.LabelFor(p => p.FirstEMail)
Html.TextBoxFor(p => p.FirstEMail, new { class = "medium", disabled = "disabled", id = "txtFirstTel" })
Html.ValidationMessageFor(p => p.FirstEMail)

1 个答案:

答案 0 :(得分:-1)

这是你的要求吗,如果我错了请告诉我

<强>型号:

[Required(ErrorMessage="FirstEMail is required")]
 public string FirstEMail{get;set;}

<强>控制器:

public ActionResult ValidatingFormMessages()
  {
      UserEmail objModel = new UserEmail();
      objModel.FirstEMail = "xxx@yy.com";
      return View(objModel);
  }
  [HttpPost]
  public ActionResult Index(UserEmail coll)
  {
      if (ModelState.IsValid)
      {
          return RedirectToAction("yourActionName", "YourControllerName");
      }
      return View();
  }

查看:

@{Html.BeginForm();}
    @Html.TextBoxFor(x => x.FirstEMail)
    @Html.ValidationMessageFor(x => x.FirstEMail)
    <input type="submit" id="btnSubmit" value="Submit" />
@{Html.EndForm();}