我在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)
答案 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();}