views:

51

answers:

1

I have the following functions in my ProceduresControlller:

Function Add(ByVal bpid As Integer) As ActionResult
    Return View(GetAvailableProcedures(bpid))
End Function

<AcceptVerbs(HttpVerbs.Post)> _
Function Add(ByVal bpid As Integer, ByVal code As String, ByVal covered As Boolean) As ActionResult
    AddProcedure(bpid, codes, covered)
    Return View("Close")
End Function

I'm loading the Add dialog via jQuery like so:

$("#dialog").load(
    "/Procedures/Add",
    { bpid: 123 },
    function(data) {
        alert(data);
    });

This is failing because it's calling the Post method (where "covered" can't be empty) instead of the Get. I tried decorating the Get with <AcceptVerbs(HttpVerbs.Get)>, but it doesn't change the outcome.

Why is this triggering the Post, and how do I get it to use the Get? I realize I could change the names to not be ambiguous, but I want to know why it won't pick the Get if I'm only passing "bpid".

+1  A: 

From the jQuery API reference for Ajax.load:

A GET request will be performed by default - but if you pass in any extra parameters in the form of an Object/Map (key/value pairs) then a POST will occur. Extra parameters passed as a string will still use a GET request.

So I guess you could change it to something like:

$("#dialog").load(
    "/Procedures/Add",
    { "bpid" : "123" },
    function(data) {
        alert(data);
    }
);

HTHs,
Charles

Charlino
Yep, completely forgot about that little fact. Thanks.
gfrizzle