locked
Ajax.ActionLink not working properly with onBegin parameter RRS feed

  • Question

  • User-644077088 posted

    I have function that is called in "onBegin" ajax option of ajax.actionlink

    function cancelAction() {
        $.ajax({
            data: { p: "test", z: "value" },
            url: '@Url.Action("DoSomething", "TestCtlr")',
            type: "GET",
            dataType: "json",
            success: function (data) {
                if (data.do == 0) { 
                     // do something
                }
    
                else {
                    alert("error message");
                }
    
            },
    
        }
        )}
    return false;
    }

    and ajax.actionlink

    @Ajax.ActionLink("Click here",//link text
      "Insert", // action name
      "Projects",  // controller
      new { poz = item.itemID.ToString() }, // route values 
      new AjaxOptions() { HttpMethod = "GET", UpdateTargetID = "PrjDiv", OnBegin = "cancelAction", OnSuccess = "Initiate_Dialog" }, // ajax options
      new { @class = "openDialog", @id = item.idemID.ToString() } //htmlAttributes
      )  

    Click on ajax.actionlink should check in database (onbegin) if there's record with parameters p and z (data) and if there's none, to call jquery ui dialog (Initiate_Dialog) to insert record in database. If record in database exists, action should be canceled ("cancelAction")

    Problem is with "//do something part" of code.

    I tried to put $.ajax(this.url) and $.ajax(this.href) there, to continue with my function, but it's not working.

    Can someone help me with this?

    Thursday, April 24, 2014 5:33 AM

Answers