.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

jQuery post to an action method

Posted By:      Posted Date: October 19, 2010    Points: 0   Category :ASP.Net


I hope this is the right section to post this, as it does seem to be an MVC related issue. I'm trying to use the jQuery.post() function to post an object to an action method, but for some reason the nested objects aren't initialised properly when they're received by the action method.

Here's my javascript code:

var data = {
    Id: 10,
    User: {
        Id: 5
$.post("/Home/SaveCompany", data, function (data) {

And my action method:

public ActionResult SaveCompany(Company company)
    if (company.Id > 0) {
    } else {
    return Json(new { id = company.Id });

company.Id has a value of 10, but company.User.Id is 0. Any ideas what I'm doing wrong? I've not named any properties incorrectly, by the way.


View Complete Post

More Related Resource Links

Looking for ASP.Net JQuery Post Sample


Hi, iam looking for a JQuery Post Sample, without reload of the current Page. I want on a webform enter a search text, onclick on the submit button i want get (webservice?) back clean html code that will be shown in a div tag
i found something like

<form id="formsearch" onsubmit="jQuery.ajax({type:'POST',dataType:'html',data:jQuery(this).serialize(),success:
function(data, textStatus){jQuery('#ajaxcontent').html(data);},beforeSend:function(XMLHttpRequest){$('#indicatorSearch').
show();},complete:function(XMLHttpRequest, textStatus){$('#indicatorSearch').hide();},
url:'/Search'}); return false;" action="/Search" method="post">

but how is the source asp.net (or webservice) build up?

can you give me some samples, how i can realize that with asp.net


Jquery Ajax Call to Mvc Action tips.


I try to do a ajax call via the jquery api.

The scritp :

$("#sortColumn").click(function(e) {
                var columnName = $(this).attr('name');
                var sidx = columnName;
                var sord = '<%= (string)ViewData["sord"] == "asc" ? "desc" : "asc"%>';
                var page = '<%= ViewData["page"] %>';
                var rows = "5";
                type: "POST",
                url: "/Mailings/GetData2",
                data: {'sidx': sidx ,'sord': sord ,'page': page ,'rows':  rows },
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(response) {
                var jsonObject = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
                error: function(xmlHttpRequest, textStatus, errorThrown) {
                    document.getElementById('infoContentHeader').innerHTML = xmlHttpRequest.responseText;


And the

Action method returning an ActionResult used in a Action method


Hell all,

I have the Index action method calling a method that itself is an action method.

Example :

public ActionResult Index()
   //do stuff
   ActionResult result = MethodB();
   // ?? what to return here ??

public ActionResult MethodB()
   //do stuff

  return View("Index);

What to do in this case ?

Overload POST with X-HTTP-Method-Override as DELETE

Hi, How do I pass POST with the override header, X-HTTP-Method-Override, which will say I really mean DELETE in REST WCF 3.5? What changes are needed exactly in server side REST code & where to make those changes exactly? Can some one post code snippet? Thanks!

Sorting GetListItems method using Jquery

Hi, I am getting the list item collection by using jquery but I am unable to do sorting based on the ows_ID. Any one can help me? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="refresh" content="120"> <title></title> <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script> <script type="text/javascript"> $(document).ready(function () { var soapEnv = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \ <soapenv:Body> \ <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \ <listName>ListName</listName> \ <viewFields> \ <ViewFields> \ <FieldRef Name='Created' /><FieldRef Name='Modified' />\ </ViewFields> \ </viewFields> \ <rowLimit>5</rowLimit>\ <strong> <OrderBy><FieldRef Name='ows_ID' Descending='True' /></OrderBy>\</strong> </GetListItems> \ </soapenv:Body> \ </so

Asp.Net MVC 2 Entity Framework Jquery Post

Hello, I am developing a project by using Entity Framework of Asp.Net MVC 2  . In the project , there is a product order  section.We can choose the product quantity and price button when click to adding button to add the product by using jquery post, -but at entity control model look empty-,  despite of If i do this process with normal post, it looks full. But In normal post, there are some disadvantages that i have to fill all form again and i have to work with many codes, but i want to use jquery  codes because of it looks more aesthetic than entity post. I am waiting for your help about this problem to develop it by using jquery codes. Note: In addition Please advise me if you have any idea about to create a system as adding a tab or adding the tab details  of products by using MCV as interactively.Hello, I am developing a project by using Entity Framework of Asp.Net MVC 2  . In the project , there is a product order section. We can choose the product quantity and price button when click to adding button to add the product by using jquery post, -but at entity control model look empty-, despite of If i do this process with normal post, it looks full. But In normal post, there are some disadvantages that i have to fill all form again and i have to work with many codes, but i want to use jquery codes because of it looks more a

jQuery & WCF Data Service - PUT Update - Rejected with 405 Method Not Allowed

I am writing a sample jQuery/WCF Data Service app to utilize OData, however I am getting a status code 405 - Method not allowed when I attempt to update an entity with a PUT Http method. I have configured my WCF Data Service as follows: public static void InitializeService(DataServiceConfiguration config) { config.SetEntitySetAccessRule("jCredentials_PINs", EntitySetRights.All); config.SetEntitySetAccessRule("jCredentials_PINTree", EntitySetRights.All); //config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; } I am attempting to update the jCredentials_PINs table. My jQuery call to update the WCF Data Service is as follows:function UpdatePIN(selectedTreeNode, updateObj) { var url = dataService + "/jCredentials_PINs(guid'" + selectedTreeNode.get_value() + "')"; var json = JSON.stringify(updateObj); $.ajax({ url: url, data: json, type: "PUT", contentType: "application/json; charset=utf-8", timeout: 10000, dataType: "json", success: AjaxPINUpdateSuccess, error: AjaxPINUpdateFailure }); } function AjaxPINUpdateSu

Programatically Send and receive data using Post Method

Hi,I wish to make a script which programatically send the POST data to one server and then the other server receive the POST message and retrieve the information. How should make this work? I already successfully write the sender site, the code as follow:string postData = "id=0&co=5";ASCIIEncoding encode = new ASCIIEncoding();         //data encoding         byte[] dataEncode = encode.GetBytes(postData);         //end ascii encoding scheme         string url = "http://localhost:51711/Handler1.ashx"; //         //web request         HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);         req.Method = "POST";         req.ContentType = "application/x-www-form-urlencoded";         req.ContentLength = dataEncode.Length;         //send data                Stream st = req.GetRequestStream();         st.Write(dataEncode, 0, dataEncode.Length);         st.Close();ASCIIEncoding encode = new ASCIIEncoding();byte[] dataEncode = encode.GetBytes(postData);stri

"Failed to load source" posting to MVC2 action with jQuery



I am trying to save user feedback by using jquery to post to an action however i am getting the error message "Failed to load source for: http://www.something.com/feedback/savefeedback" this code works fine on localhost but not when put on my shared hosting, this doesnt just affect this query post but also at least one other.

below i have the route from the global.ascx, the action int the FeedBackController and the query that does the post.

"FeedBack",           // Route name
"FeedBack/{action}",  // URL with parameters
new { controller = "FeedBack", action = "SaveFeedBack", id = "" }  // Parameter defaults

 public bool SaveFeedBack(string FeedBack, string SubmitName, string email)

$.post("/FeedBack/SaveFeedBack", { FeedBack: feedbackText, SubmitName: SubmitName, email: email }, function(data) {

if (data == "True"){}

else {}


create web service with http-post method


hi All,

we need to expose a web service to the 3rd party vendor which can only call using POST protocol, NOT SOAP.

So my question, is it better to build a web service or just simply .aspx page?

Also is there any best practice documentation on this.



Method 'Post' of object 'IOWSPostData' failed


I have Microsoft Office 2003 and Microsoft Sharepoint Designer 2007 on the
same machine. I have a problem uploading an excel spreadsheet into WSS 3.0.
I get Method 'Post' of object 'IOWSPostData' failed error. I have followed
this article (http://mindsharpblogs.com/Kathy/archive/2008/03/16/4450.aspx)
but it doesn't resolve the issue.
Pls, advise how can I resolve this.

Thank you in advance!


Get and Post method in C#


I need an example of GET and POST methods for C #?

whether one can explain it in a textbox how it works.

Thank you in advance

get() method of Jquery not properly working in IE



 I used get method for getting JSON data from .aspx page.This JSON data for chart application which show monthly records.For selecting month I used dropdown and defaultly I set current month chart.But for showing previouse month records in chart   i want to select the  previouse month but chart not shows selected Month record rather than it shows default record.

Run jQuery script after each form post in mvc2 app


I need to exec some js each time a page loads, and also every time a view is returned after a post action.  I use jQuery.ajax to post form - using url of Controller/Action.  Post is successful and response data is correct, but my js doesn't get called.

I had js in a script tag, within the head of my view.aspx, and found that it does not execute each time the response is received after a post action.  I also tried calling this within $(document).ready, but this does not execute after post action.  window.onload also does not exec after post action.

I prefer not to use MS AJAX js lib, but if there is some pageLoad function, I will give it a try.

Is there a native javascript event that is raised when http response is received?  Thanks.

Sending JSON Array to an ASP.NET MVC Action Method Argument


 <input type = "submit" onclick = "savePayment()"  value = "Test"/>

    <script type="text/javascript">
        function savePayment() {
            //Creating some test data
            var lineItems = new Object();
            lineItems.Entrys = new Array();
            lineItems.Entrys[0] = new Object({ Name: "Dung", Age: "21"});
            lineItems.Entrys[1] = new Object({ Name: "An", Age: "25" });

            //Posting them to server with ajax
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                url: '<%=Url.Action("TestArray", "Json") %>',
                dataType: 'json',
                data: $.toJSON(lineItems),
                success: function (result) {
                    if (result) {
                    else {

Jquery - Ajax Get Method


I have a web service:

public string GridAjx(int Input1, int Input2) 

I would like to use Jquery to make a link that reads GridAjx function using AJAX.
To retrieve the hidden parameters.
I found a solution through:
<a href="" rel="ID"> </ a>
But it would be only one parameter.
I need to pass two parameters.
Thanks for the advice.

Requires action parameters as POST


hi guys, may be a simple question, but I can't find the answer.

For various reasons, I want my controller's actions to only be accessed via post. Thats easy, simply use [AcceptVerbs(HttpVerbs.Post)] and done.

Now, I'd like to force the requests to use post for the parameters. With [AcceptVerbs(HttpVerbs.Post)], as long as the request is done as post, the parameters can still be sent via the query string. 

Is there a way to force them to come from post variables? (ASP.NET MVC 2)


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend