タイプ送信の入力を使用しないことをお勧めします。代わりに、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 を有効にせずにクライアントをサポートする場合は、オプションではない可能性があります)。