0

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

3
  • You can't make redirect with AJAX call (at least not this way). In your current code you will send a 3xx response code to the browser, which will be ignored. What you should do is responding with data or markup which you use in your success handler for updating the page. On the other hand, what is the point of making AJAX call if you want to redirect? Commented May 31, 2010 at 12:46
  • ok so what to return I will be returning json ? Commented May 31, 2010 at 12:59
  • If you want to return JSON, then prepare a data object and return it with JsonResult (you can use Json() method of controller) Commented May 31, 2010 at 19:57

1 Answer 1

2

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.