我已經創建了一個接觸的形式,該模型由簡單..產品名稱,電子郵件,電話號碼等MVC - Ajax.BeginForm - 發佈多次
在模型我有一些一些簡單的必需屬性屬性。
這一切都很好,當沒有驗證錯誤發生時我收到一封電子郵件說已提交表單,並向用戶顯示一個很好的「謝謝」消息。
我的問題是驗證失敗。我在文本框等上獲得了通常的紅色邊框。現在,如果用戶更新文本框以符合驗證要求並再次提交,我收到兩封電子郵件。他們兩個完全相同的細節。似乎很多時候,驗證失敗的原因是我收到了多少個電話(電子郵件)。
我對MVC來說很新,所以如果你能指出我的方向,那就太棒了。
乾杯,
Ĵ
形式:
using (Ajax.BeginForm("ProcessContact", "Contact", null, new AjaxOptions { UpdateTargetId = "subContentWrapper", }))
{
@Html.ValidationSummary()
<p>
<strong>Please tell us a little about you and the nature of your enquiry </strong>
</p>
<table>
<tr>
<td style="width: 200px;">
Name:
</td>
<td>@Html.TextBoxFor(x => x.Name, new { @class = "textBox" })
</td>
</tr>
<tr>
<td>
Company Name:
</td>
<td>@Html.TextBoxFor(x => x.CompanyName, new { @class = "textBox" })
</td>
</tr>
<tr>
<td>
E-mail:
</td>
<td>@Html.TextBoxFor(x => x.Email, new { @class = "textBox" })
</td>
</tr>
<tr>
<td>
Phone:
</td>
<td>@Html.TextBoxFor(x => x.Phone, new { @class = "textBox" })
</td>
</tr>
</table>
<br />
<br />
<p style="text-align: center">
<input type="submit" value="Contact Us" /></p>
}
}
代碼:
if (ModelState.IsValid)
{
if (ContactService.ProcessContactSubmission(model))
{
ViewBag.Sent = true;
}
else
{
ViewBag.Sent = false;
ModelState.AddModelError("", "Sorry an error has occured, please try again later.");
}
return PartialView("~/Views/Modules/Contact Us/Main.cshtml", model);
}
else
{
ViewBag.Sent = false;
return PartialView("~/Views/Modules/Contact Us/Main.cshtml", model);
}
ContactService.ProcessContactSubmission(模型) - 這只是發送電子郵件,並返回真/假
你可以發佈您的代碼PLZ? –
我已更新帖子以包含代碼snipplet。謝謝 – Diginari
什麼是「subContentWrapper」?它是圍繞AJAX表單的DIV嗎? – Moshe