2016-05-07 3 views
0
コントローラーで

:ビューでサブミット型入力のタスクを指定する方法は?

[HttpPost] 
public ActionResult UnAssign() 
{ 
    ViewBag.Message = courseManager.Updated(); 
    return View(); 
} 

:私はUpdateメソッドで0に私のデータベースの列値の1を更新したいこのコードで

<form method="post">   
     <input id="btnSubmit" type="submit" value="UnAssign Courses" /> 
    </form> 
    @section scripts 
    { 
     <script> 
      $("#btnSubmit").click(function(event) { 

       event.preventDefault(); 

      }); 
      $("#btnSubmit").click(function(event) { 

       var confirmationmessage = "Are you sure you want to delete this?"; 

       if (! confirm(confirmationmessage)) { 


        event.preventDefault(); 

       } else { 



       } 
      }); 
     </script> 
    } 

私はすでに行わ一緒にクエリを作成しましたデータベースとの接続。私は特定のアクションメソッドを呼び出すことができますし、どのようなモデルや値を渡すことなくこのタスクを行うことができます知っていることを知っている何もしません。

+0

Ajaxポストを使用できます。 – Berkay

+0

'

'の 'action'属性は、あなたがヒットするコントローラアクションを決定します。 'event.preventDefault()'で通常のフォームの送信を無効にしたので、ボタンを押してもコードは何もしません。 – Jasen

+0

その部分を変更しましたが、まだ私の提出は私の行動には向かない。私はフォームアクションの呼び出しを試みたが、何もしなかった。 –

答えて

0

あなたは少しはあなただけの1つのifステートメントを使用して否定文字を削除することができ、あなたのコードをクリーンアップするには2つの.clickハンドラ

$("#btnSubmit").click(function(event) { 
      event.preventDefault(); 
      var confirmationmessage = "Are you sure you want to delete this?"; 

      if (! confirm(confirmationmessage)) { 

       //You do not need these here. Get rid of it 
       //event.preventDefault(); 

      } else { 

       //here submit your form 
       $('form').first().submit(); 

      } 
     }); 

を必要としません。

if (confirm(confirmationmessage)) { 

       $('form').first().submit(); 

      } 
    //jquery code does nothing after this. You already used event.preventDefault(); so the form will not be submitted 

私もあなたにもMVCスタックを使用する場合があり、MVCを使用しているので、Html.BeginFormAjax.BeginFormを使用する方法をルックアップするためにあなたを助言します。

http://www.c-sharpcorner.com/UploadFile/3d39b4/working-with-html-beginform-and-ajax-beginform-in-mvc-3/

関連する問題