Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, sir

I am developing a mvc web application in mvc 3 razor and i want to send list(Grid View) object from view to Controller using ajax call in mvc.

example:-

<script>
$("#btnsave").click(function () {
debugger
var UserName = $("#UserName").val();
var Password = $("#Password").val();

$.ajax({
url: '@Url.Action("Add_New_Access1", "Form")',
type: "GET",
data: { UserName: UserName, Password: Password, str: Gv_Table_List },
success: function (data) {
alert("Save", "Data Saved Successfully")
}
});
});
</script>

Here Gv_Table_List is my List Which I take instead of GridView

and what kind of type i should take in controller
for str
please help..
Posted
Updated 6-Jun-15 1:29am
v2

1 solution

You use jquery function to do the call for submitting the data to the controller. Your function may look like this:
HTML
$('#YourLink').click(function () {      
    $.ajax({
        url: http://{hostname}/Person/Search,
        type: 'GET',
        data: { 
                id: "@ViewBag.ID",
                name: "@ViewBag.Name" 
              },
        success: function () {
        },
        error: function () {                
        }
    });


and in the controller call you can write as below to grab the data

C#
public ActionResult Search(int id, string name)
{
   //Do the code for searching
}


Hope this will help.
 
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