Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
In Asp.net when we make ajax call we make method as static.
[WebMethod]
public static string GetMessage()
{   
    return "Dummy Message";
}

but in MVC we do not need to make Action static?
WHY SO? are action by default static?
Posted
Comments
Sreekanth Mothukuru 14-Jul-15 2:07am    
comparing both web methods and action methods in mvc is not right because both follow different patterns.
MVC will have router which will redirect the user request to appropriate controller's action method. Also, we have task and await keywords to do async when required.

Web methods are static because they should be accessible from client side even without creating an object to the container class. This is the basic difference. Hope you understand.

1 solution

You can find a good discussion over the key tops below

- Why do ASP.NET AJAX page methods have to be static?[^]

- ASP.NET MVC controllers static methods[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900