0

jQuery の目立たないクライアント側検証で ASP.Net MVC を使用しています。次のようなボタンがあります。

<input type="submit" name="SubmitButton" value="Add Item" class="cancel" />

通常、送信ボタンは POST 呼び出しを行い、新しいアイテムをリストに追加します。明らかに、この目的のために、検証は必要ありません。これは正常に機能します。

問題は、ページがリロードされる前に、すべてのフィールドの検証エラー メッセージが短時間表示されることです。

目立たない検証スクリプトがこれを引き起こしているのか、それともjQuery検証のバグなのかを検索しました。

何か案は?


更新:私の質問をより明確にするために:

望ましい状態は次のとおりです。ボタンが「キャンセル」としてマークされている場合、エラー メッセージが表示されずにフォームがポストバックされます。

現在の状態は次のとおりです。ボタンが「キャンセル」としてマークされている場合、フォームはポストバックされますが、エラーメッセージが表示されます!!

4

1 に答える 1

0

タイプ送信の入力を使用しないことをお勧めします。代わりに、html アンカー (リンク) または MVC の Html.ActionLink を使用して、ページをリロードするか、どこかにリダイレクトしてください。
ここに投稿された同様の質問:フォームのキャンセルボタン

更新 1 - @sam360 コメントによると

キャンセル ボタン リクエストを処理する必要があるアクション メソッドに MultiButtonAtribute を配置することができます。

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class MultiButtonAttribute : ActionNameSelectorAttribute
{
    public MultiButtonAttribute(string matchFormKey) : this(matchFormKey, null) {
    }

    public MultiButtonAttribute(string matchFormKey, string matchFormValue) {
        this.MatchFormKey = matchFormKey;
        this.MatchFormValue = matchFormValue;
    }

    public string MatchFormKey { get; set; }
    public string MatchFormValue { get; set; }

    public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
    {
        string value = controllerContext.HttpContext.Request[MatchFormKey];
        return value != null && (value == MatchFormValue || MatchFormValue == null);
    }
} 

ボタンの名前 (「キャンセル」) がリクエストで一致する場合、計算されたキャンセル アクションがリクエストを処理します。

[HttpPost]
[MultiButton("cancel")]
public ActionResult CancelAction(MyModel model)
{
 // ... update the model (e.g. remove the last item from list and return the view with updated model
}

そして、次の形式になります。

<input type="submit" name="cancel" value="Remove Item" class="cancel" />

でもよくわかれば。何らかのフォームで入力を動的に追加/削除したい。一部のサーバー要求を保存するために、javascript または jQuery 関数を使用してクライアント側で実行することを検討する必要があります (ただし、javascript を有効にせずにクライアントをサポートする場合は、オプションではない可能性があります)。

于 2012-11-10T13:21:43.300 に答える