Click here to Skip to main content
11,929,166 members (57,202 online)
Rate this:
Please Sign up or sign in to vote.
This seems easy but is not just working for me. I have the following code to run a method in my HomeController from my javascript file
   url: '/HomeController/MethodName,
   data: { id: id }
   success: function(data){
    alert('Sucess ' + data);      
My method is
public string MethodName(int id)
   return id.ToString() + "test ";

The view calling the javascript has the following scripts defined: jquery.unobtrusive-ajax.min.js, MicrosoftMvcAjax.js, MicrosoftAjax.js, validate.unobtrusive.min.js, jquery.validate.min.js

But is is not just working. Nothing happens. The first alert of the function do show up. But nothing else after that.
Posted 17-Jan-13 9:00am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Close, but not quite how it works. Here is a sample of how it should look.
     type: 'GET',
     url: '/YourController/YourMethod',
     dataType: 'json',
     async: false,
     data: { arg1: 'arg1value',
             arg2: 'arg2value'
     success: function (result) { alert(result); },
     error: function (jqXHR, textStatus, errorThrown) {
               alert( 'An error occured while loading: ' + textStatus + ": " + errorThrown + ": " + jqXHR.responseText );
public JsonResult YourMethod(string arg1, string arg2)
   // Do something to get a result...
   string yourResult = "Some soft of result.";
   return Json(yourResult, JsonRequestBehavior.AllowGet);
Espen Harlinn 17-Jan-13 18:12pm
Marcus Kramer 17-Jan-13 18:38pm
Thanks, Espen

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 17 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100