2009-07-23 24 views

Trả lời

27

Bạn có thể kiểm tra Request.HttpMethod để biết điều đó.

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

Bạn có thể tách các phương pháp điều khiển của bạn:

[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

Ý tưởng tuyệt vời. Cảm ơn bạn – Alex

+1

Tôi nghĩ rằng bạn NÊN serpate phương pháp điều khiển của bạn ... – sesispla

0

Bạn cũng có thể sử dụng ActionResults Đối Nhận và gửi các phương pháp riêng biệt như sau:

[HttpGet] 
public ActionResult Operation() 
{ 

    return View(...) 
} 


[HttpPost] 
public ActionResult Operation(SomeModel model) 
{ 

    return View(...); 
} 
Các vấn đề liên quan