0

Isend the some aruguments to controller using ajax but it does not return the value.

My concept : selected @html.dropdownlist value i send to the controller , using this value thats perfrom the get the valus for bind the property to another dropdownlist using mvc3

IGot this answer : verfif given link

verfif given link

Community
  • 1
  • 1
user279
  • 65
  • 3
  • 11
  • What are you sending ? Please post some code, it tells what have you tried – Karthik Chintala Feb 07 '13 at 06:24
  • Put a breakpoint in the Controller method you are calling and make sure it is actually returning some data (this will also tell you if the controller was hit or not). You can also use Fiddler2 to examine the contents of the AJAX request/response http://www.fiddler2.com/fiddler2/. In terms of debugging the JavaScript, you can use the `console.log` function http://blogs.msdn.com/b/cdndevs/archive/2011/05/26/console-log-say-goodbye-to-javascript-alerts-for-debugging.aspx. Once you have done all three, you should be able to drill down to the source of the issue pretty quickly. – Aaron Newton Feb 07 '13 at 21:48

1 Answers1

0

you are passing type option in ajax twice and the url is not formatted properly

function onChange(bookid) { 
          $.ajax({
            type: "GET",
            url: '@Url.Action("books","subject")',
            data : { bookid: bookid},
            dataType: "json",
            success: function (result) { 
              alert('success');
              //do whatever you want
            },
            error: function(result){
            }
        }); 
    };

You are passing dataType as json. So, if you want to hit the success result for $.ajax, you need to return Json from your action result instead of returning as View.

When you return as View it gives error always.

    public ActionResult books(string bookid)
    {

        var books= service.books(projectId); 

        // books are stored in list format
        return Json(books);
    }

Hope it helps you.

Karthik Chintala
  • 5,465
  • 5
  • 30
  • 60