tags:

views:

41

answers:

1

Controller:

   public ActionResult EditOrganizationMeta(int id)
    {

    }


        [HttpPost]
    [ValidateInput(false)]
    public ActionResult EditOrganizationMeta(FormCollection collection)
    {

    }

View:

function DoAjaxCall() {
        var url = '<%= Url.Action("EditOrganizationMeta", "Organization") %>';
        //url = url + '/' + dd;

        $.post(url, null, function(data) {
            alert(data);


        });
    }

  <input type="button" name="something"  value="Save" onclick="DoAjaxCall()" /> 

how would i make the ajax call , i have basically two functions with the same name EditOrganizationMeta,Do the form collection will be passed automatically.Basic confusion is regarding the method call

Ok i made a call by ajax but after that My This code is not running anymore

  [HttpPost]
    [ValidateInput(false)]
    public ActionResult EditOrganizationMeta(FormCollection collection)
    {
        int OrganizationId = 11;
        string OrganizationName = "Ministry of Interior";

        try
        {    
             string ids = Request.Params // **getting error here some sequence is not there** 
            .Cast<string>()
            .Where(p => p.StartsWith("button"))
            .Select(p => p.Substring("button".Length))
            .First();

             String RealValueOfThatControl = collection[ids];


            }

        }
        catch { }


        return RedirectToAction("EditOrganizationMeta", new { id = OrganizationId });

    }

I think that there is no post

+2  A: 

You have to pass the data you want through second parameter of $.post call. The easiest way (if you want to post a form) is to use $.serialize like this:

$.post(url, $('#formId').serialize(), function(data) { 
  alert(data); 
});

Where 'formId' is you form identifier. And don't worry about having two methods with same name, they will be distincted by HttpVerb (one will respond only to GET, while second to POST).

tpeczek