2009-07-23 9 views

答えて

27

これはRequest.HttpMethodです。

if (Request.HttpMethod == "POST") { 
    //the controller was hit with POST 
} 
else { 
    //etc. 
} 
10

あなたのコントローラメソッドを分離することができます:

あなたはまた別に以下のようにGETとPOSTメソッドの場合ActionResultsを使用することができます
[AcceptVerbs(HttpVerbs.Get)] 
public ViewResult Operation() 
{ 
    // insert here the GET logic 
    return SomeView(...) 
} 


[AcceptVerbs(HttpVerbs.Post)] 
public ViewResult Operation(SomeModel model) 
{ 
    // insert here the POST logic 
    return SomeView(...); 
} 
+0

素晴らしいアイデア。ありがとうございます – Alex

+1

私はあなたのコントローラのメソッドを蘇らせるべきだと思います... – sesispla

0

[HttpGet] 
public ActionResult Operation() 
{ 

    return View(...) 
} 


[HttpPost] 
public ActionResult Operation(SomeModel model) 
{ 

    return View(...); 
} 
関連する問題