I have a method (no '[HttpPost]' => GET?)
public class HomeController : Controller { public async Task<ActionResult> UserFriendsPartial(int userId, int count) { var friends = await RelationshipService.GetFriendsByUserId(userId, count); return PartialView(friends); } } Have a presentation
<div id="UserFriends"> @Html.Action("UserFriendsPartial", "Home", new { userId = Model.Id, count = 6 }) </div> <button id="AddToFriends"/> <script type="text/javascript"> $('#AddToFriends').click(function () { FriendsRefresh(6); }); function FriendsRefresh (pCount) { var p = { userId: @Model.Id, count: pCount }; $.ajax({ url: '@Url.Action("UserFriendsPartial", "Home")', type: 'POST', contentType: "application/json;charset=utf-8", data: JSON.stringify(p), success: function (data) { $('#UserFriends').html(data); } }); } </script> When the page is loaded, the method is called via Html.Action (if you add the HttpPost tag in the controller to the method, it will not work). And when you press the button, the same method is called an AJAX POST request. The question is why does this work?