0
我試圖把登錄和註冊表單的自定義錯誤消息。在mvc剃鬚刀中的錯誤消息位置
到目前爲止,我有形式,以檢查是否有一個電子郵件已經註冊,如果是,它會返回
Response.Write("There's already someone with that email")
但這個問題是這條消息將只出現在的頂部網站。
有沒有一種方法可以在其他地方顯示這些錯誤消息?
我知道,在我的模型可能只是把
[Required(ErrorMessage = "Something here")]
然後只是把視圖某處
@Html.ValidationMessageFor(a =>a.Email)
,它會顯示的錯誤。
,我對現在的代碼是這樣的:
[HttpPost]
public ActionResult Register(Registration signingUp)
{
var db = new ShareRideDBEntities();
if (ModelState.IsValid)
{
//find if email is already signed up
var FindEmail = db.tblProfiles.FirstOrDefault(e => e.PROF_Email == signingUp.Email);
//if email is not found up do this
if (FindEmail == null)
{
var Data = db.tblProfiles.Create();
Data.PROF_Password = signingUp.Password;
Data.PROF_Email = signingUp.Email;
db.tblProfiles.Add(Data);
int Saved = db.SaveChanges();
if (Saved != 0)
{
Response.Write("Registration Successful.");
}
else
{
Response.Write("There was an error.");
}
}
else
{
Response.Write("There's already an user with that email.");
return View();
}
}
else
{
Response.Write("Fill all the fields to continue.");
}
return View();
現在,如果我這樣做與現有電子郵件將返回「已存在使用該電子郵件的用戶。」但它會顯示在網站的頂部。
我怎樣才能讓這個錯誤消息顯示在別的地方?
我聽到@ Html.Raw()的東西,但我很困惑如何使用它。
感謝您的快速回答,非常簡單,謝謝! –