0

I am using X-Editable Plugin in Asp.net with jquery Datatables to edit my table. I'm using jQuery $.ajax() Method to make a call to a method in the controller but it's not hitting that method when this function is called. Anyone know how to work jQuery $.ajax() Method?

$('#example').dataTable();
"fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {                  
               $('td', nRow).wrapInner('<a class="xediable-example" href="#"></a>').editable({
                   type: 'text',
                   pk: 1,
                   name: 'test',
                   url: function (params) {                           
                         var urlj = "TestMethod"
                           return $.ajax({
                           type: 'POST',
                           url: urlj,
                           data: JSON.stringify(params),
                           contentType: 'application/json; charset=utf-8',
                           dataType: 'json',
                           async: false,
                           cache: false,
                           timeout: 10000,                              
                       });
                   }
               });                   
               return nRow;
           }
       });

Control method:

public static string TestMethod(string name, string pk, string value)
{
    return "" ;
}

Error message :

Erreur du serveur dans l'application '/'.La ressource est introuvable. Description : HTTP 404. La ressource recherchée (ou l'une de ses dépendances) a peut-être été supprimée ou renommée ou bien elle n'est plus disponible temporairement. Vérifiez l'URL ci-après et assurez-vous qu'elle est correcte. URL demandée: /H41_TitreConge/TestMethod Informations sur la version : Version Microsoft .NET Framework :4.0.30319; Version ASP.NET :4.0.30319.17929
Raidri
  • 17,258
  • 9
  • 62
  • 65
  • 2
    `TestMethod` needs to be a controller action, I'm guessing it isn't. – Mister Epic Sep 26 '13 at 11:28
  • 1
    I agree with @Chris. Your TestMethod() is static, it means that it's located in static class also. But ASP.NET MVC doesn't allow static controllers or actions, so your TestMethod() couldn't be called by MVC - [explanation why it's done like that](http://stackoverflow.com/a/6127153/815960) – kasitan Sep 26 '13 at 11:41

4 Answers4

0
var urlj = "TestMethod"

Is not a valid URI.

Change it to http://://TestMethod however your set up your environment.

Just try to access the TestMethod in your browser if you type in the service URL/TestMethod, it should actually give you some reasonable message.

MichaC
  • 13,104
  • 2
  • 44
  • 56
0

Your URL should be:

var urlj = '/YOUR_CONTROLLER_NAME/TestMethod'

Your test method must be like this:

[HttpPost]
public JsonResult TestMethod(string name, string pk, string value)
{
    return Json( ... )
}
Alex Costa
  • 306
  • 1
  • 10
  • @user2819112 your TestMethod can't be `static` and it should return an `ActionResult` (or `JsonResult`). Check my edited answer. – Alex Costa Sep 26 '13 at 13:31
0

Try this:

var urlj = "@Html.Action("TestMethod")"
karaxuna
  • 26,752
  • 13
  • 82
  • 117
0

By changing the Url to this also works ! Give it a try,

url: '@Url.Action("ActionName","ControllerName")',
AthibaN
  • 2,087
  • 1
  • 15
  • 22