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

I have the following code in my Jquery MVC application:


<script type="text/javascript">
$(document).ready(function () {
$("#.Submit").click(function () {
checkValidate();
var Name = $('#Name').val();
var Mobile = $('#MobileNumber').val();
var Email = $('#Email').val();
var Password = $('#Password').val();

var list = ["{Name: '" + Name + "',Mobile: '" + MobileNumber + "',Email: '" + email + "',Password: '" + Password + "'}"]
var jlist = $.toJSON(list);


$.post("/Shipper/AddProfile/", { jsonData: jlist },
function(data, textStatus) {
if (textStatus != "success") {
result = "false";
}
});
}
});

});

</script>

I was wondering if anyone can help me with the Controller Action code to insert this to the SQL database. It should Submit the following form:
CSS
Name
Mobile Number:
Email:
Password:


Submit Cancel.

Any help will be appreciated.
Posted

1 solution

Hey
have you considered using Linq to SQL in your model?? highly recommend it:

http://www.google.com/search?gcx=w&sourceid=chrome&ie=UTF-8&q=linq[^]

also -
your shippercontroller's action will look like this:
C#
public JsonResult AddProfile(string Name, string Mobile, string Email, string Password)
{
   JsonResult result = null;
   ShipperModelDataContext smdc = new ShipperModelDataContext();
   smdc.spc_CreateProfile(Name, Mobile, Emaill, Password);
   smdc.dispose;
   result = { valid: true, returnMessage: "Inserted" };
   return result;
} 


I hope this at least puts you on the right track.

-Jeremy
 
Share this answer
 
Comments
bridgite 7-Mar-12 10:15am    
Hey Jeremy,

Thanx for the reply. I am already using LINQ. I tried using the code above but
[result = { valid: true, returnMessage: "Inserted" }; and myDataContext.dispose;] cause errors.
How do i pass a value returned to its corresponding field in LINQ?i.e value Name to 'Name' field in LINQ,value Mobile to 'Mobile' field in LINQ e.t.c?


I am really new to this so forgive me if i seem to be asking some questions that may seem 'easy' to solve :)

Thanx.

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