MVC 2ベースのWebサイトに、迷惑メール対策のCAPTCHAイメージを持つ連絡フォームがあります。MVCフォーム投稿を更新する画像を更新する
ほとんどのフォームを完了した後、ユーザーは画像を読むことができないと判断します。そのため、ユーザーは別の画像でページを更新することができます。これにより、フルページリロードが発生します(これは問題ありません)。
既存のデータを残すためにページ全体をロードして、代わりに別のイメージを表示するだけです。
したがって、値を保持し、検証をトリガーしないアクションを呼び出すにはどうすればよいですか?
ここで私が持っている問題は... 1.検証をトリガせずに投稿を実行する方法を教えてください。 2.フォームの値はどのように維持しますか?
私はAJAXソリューションに興味がなく、私はreCAPTCHAに興味がありません。
ありがとうございました。 Dan。
私は解決策があると思います - フィードバックを歓迎します!あなたが奪還ない場合
// All buttons on a form are post to the same action method so read in the value of the submit buttons to take appropriate action.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult sendlink(BusinessLinkModel linkToCreate, string button)
{
// Validation logic
if (string.IsNullOrWhiteSpace(linkToCreate.BusinessTitle)) ModelState.AddModelError("BusinessTitle", "Business title is required.");
string submitButtonName = button;
// If we want to "reload" the captcha image, then we'll clear all the errors, do nothing with the data but update the session so the image
// is re-generated appropriately.
if (submitButtonName == "reload")
{
// Clear the errors - hacktastic!
foreach (ModelState item in this.ModelState.Values.ToList())
{
item.Errors.Clear();
}
ResetSecurityCode();
}
return View();
}
// This is the image url i.e. /home/GenerateSecurityImage
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult GenerateSecurityImage()
{
string code = Session["CAPTCHA_Contact"] == null ? ResetSecurityCode() : Session["CAPTCHA_Contact"].ToString();
Response.ContentType = "image/jpeg";
GenerateImage(code, 180, 70).Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.End();
return View();
}
私の最終バージョンでは、検証チェックを実行せず、それらをクリアすることが明らかです。検証チェックは、実際の最終送信ボタンだった場合にのみ実行されます。その時点で小さなビットがハッキリしています。すべてのエラーをラウンド解除してループしています。これはちょっと神経質です。つまり、ネストされたフォームやファンシーなmvcの場合はわかりません。また、私は1週間だけMVCを使用しているので、私は自己告白n00bです! –