0

I am trying to get an Ajax call to my controller and pass back a string... for some reason, I am unable to get down into my controller... Not sure what I am missing...

$.ajax({
                url: dummyURL,
                success: function (result) {
                    $('#resultDiv').append('<b>' + result + '</b>');
                    setTimeout(function () {
                        window.location = RedirectUrl;
                    }, 1000);
                }
            });

This is how I set up my url string:

var dummyURL = '@Url.Action("AddPatient", "AddFoundPatient", new { FirstName = "-1", LastName = "-2", DOB = "-3", MRN = "-4", EMPIID = "-5", popID = (int)TempData["POPULATIONID"] })';

var FName = rowData['First_Name'];
            var LName = rowData['Last_Name'];
            var DOB = rowData['DOB'];
            var MRN = rowData['medipacId'];
            var EMPIID = rowData['EMPIID'];
            //Add Patient call
            var path = dummyURL.replace("-1", FName);
            path = path.replace("-2", LName);
            path = path.replace("-3", DOB);
            path = path.replace("-4", MRN);
            path = path.replace("-5", EMPIID);

This is the Action method that I am attempting to call...

public string AddFoundPatient(string FirstName, string LastName, string DOB, string MRN, string EMPIID, int popID)

This is the query string that I generate...

/AddFoundPatient/AddPatient?FirstName=BETTY &amp;LastName=WHITE &amp;DOB=1925-10-25 &amp;MRN=840108105 &amp;EMPIID=11011833 &amp;popID=2

I never hit the debbugging statements inside my action... What am I doing wrong?

3
  • There's something about the way ASP.NET syntax and JavaScript syntax overlap that makes me feel like I'm reading a foreign language. Or maybe advanced calculus. Commented Jul 25, 2012 at 21:31
  • Did you run Firebug or the Chrome/IE developer tools? Is the request even being made? To what URL? Commented Jul 25, 2012 at 21:31
  • Does the ajax call give an error? You can add the error function after success like so { url.., success:.., error:function(){ console.log( arguments ) }}. api.jquery.com/jQuery.ajax Commented Jul 25, 2012 at 21:33

1 Answer 1

3

The controller and action are mixed up

var dummyURL = '@Url.Action("AddFoundPatient", "AddPatient", new { FirstName = "-1", LastName = "-2", DOB = "-3", MRN = "-4", EMPIID = "-5", popID = (int)TempData["POPULATIONID"] })';
Sign up to request clarification or add additional context in comments.

1 Comment

I would try calling the service directly from your browser first, and try getting it to hit the breakpoint. Or you could use Fiddler.

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.