Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am new to MVC and Razor tools. I have a query that can i use multiple Http Post on a single page. I have a page which has multiple submit buttons for performing different jobs. So i need a to sent request from the client side to server side multiple times. SO is there any way to do it, Just as we used to do in simple asp.net by calling the event on a button click and running it on server side as and when needed. Can i do the same here??? Thank you.
Posted

Yes, MVC allows for multiple forms per page. ASP.NET WebForms only allowed one.

A simple Google for "asp.net mvc multiple post buttons[^]" would have to told you that.
 
Share this answer
 
Comments
mrbonny7 25-Nov-13 0:22am    
Thank you so much for your guidance
Yes, you can use multiple http post by using AJAX call. You can call http post method as mentioned below :

Below is the code of my http post method which excepts one parameter string UserId

C#
[HttpPost]
public ActionResult DeleteUser(string UserId)
{
 // Code to delete user
}


Below is my AJAX call to this method :

JavaScript
$.ajax({
       url: '/[ControllerName]/[MethodName]/',
       type: 'POST',
       data: {"UserId": 1},
       cache: false,
       success: function (res) {
         alert('success');
       },
       fail: function(res)
       {
          alert('fail');
       }
      });


Note: This AJAX call can be called by calling JavaScript method on button click event.
 
Share this answer
 
v2
Comments
mrbonny7 25-Nov-13 0:22am    
thank you... i got it
CodeBlack 25-Nov-13 0:32am    
don't forget to mark it as an answer and rate this solution. so that it may help other users as well.

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