Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. MVC4 Ajax call does not reach controller method

MVC4 Ajax call does not reach controller method

Scheduled Pinned Locked Moved ASP.NET
questionhtmlhelp
3 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MYSHKSL
    wrote on last edited by
    #1

    I am new to MVC4. I am trying to issue ajax call on the button click to receive partial view with the loaded dropdown list. It looks like Ajax call never reaches controller's method GetMyList(). What is wrong with my code ? Thank you //in mypage.cshtml @model IEnumerable @{ ViewBag.Title = "MyPage"; Layout = "~/Views/Shared/_MyLayout.cshtml"; }

    ....

    Find

    @Html.Partial("_MyPartialView", Model) // displayed on initial page load

    ...

    @section MySection{ $('#btnGetList').on('click', function (event) { alert("go get list"); // shows up var myName = "Jo"; $.ajax({ type: "POST", url: "Main/GetMyList", data: myName, success: function (data) { alert("list is here"); //does Not show up $("#divWithPartialView").html(data); } }); alert("after ajax"); //shows up }) } // Controller namespace MyProject.Controllers { public class MainController: Controller { ............ [HttpGet] public ActionResult MyPage() { List myList = new List(); return View(myList); } public ActionResult GetMyList(string myName) { MyModel mm = new MyModel(); List myList = mm.GetNames(myName); // using search criteria entered on the previous Application page return PartialView("_MyPartialView", myList); } } } //Partial View: _MyPartialView.cshtml @model IEnumerable Select your name: - select name - @foreach (var name in Model) { @name.myName } //Model public class MyModel { public int id { get; private set; } public string myName { get; set; } public List GetNames(strin

    Richard DeemingR P 2 Replies Last reply
    0
    • M MYSHKSL

      I am new to MVC4. I am trying to issue ajax call on the button click to receive partial view with the loaded dropdown list. It looks like Ajax call never reaches controller's method GetMyList(). What is wrong with my code ? Thank you //in mypage.cshtml @model IEnumerable @{ ViewBag.Title = "MyPage"; Layout = "~/Views/Shared/_MyLayout.cshtml"; }

      ....

      Find

      @Html.Partial("_MyPartialView", Model) // displayed on initial page load

      ...

      @section MySection{ $('#btnGetList').on('click', function (event) { alert("go get list"); // shows up var myName = "Jo"; $.ajax({ type: "POST", url: "Main/GetMyList", data: myName, success: function (data) { alert("list is here"); //does Not show up $("#divWithPartialView").html(data); } }); alert("after ajax"); //shows up }) } // Controller namespace MyProject.Controllers { public class MainController: Controller { ............ [HttpGet] public ActionResult MyPage() { List myList = new List(); return View(myList); } public ActionResult GetMyList(string myName) { MyModel mm = new MyModel(); List myList = mm.GetNames(myName); // using search criteria entered on the previous Application page return PartialView("_MyPartialView", myList); } } } //Partial View: _MyPartialView.cshtml @model IEnumerable Select your name: - select name - @foreach (var name in Model) { @name.myName } //Model public class MyModel { public int id { get; private set; } public string myName { get; set; } public List GetNames(strin

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      You have posted the same question twice: http://www.codeproject.com/Messages/4692608/MVC4-Ajax-call-does-not-reach-controller-method.aspx[^] http://www.codeproject.com/Messages/4692604/MVC4-Ajax-Call-does-not-reach-controller.aspx[^] Read this[^], and pay attention to point 9:

      do not post the same question in more than one forum


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      • M MYSHKSL

        I am new to MVC4. I am trying to issue ajax call on the button click to receive partial view with the loaded dropdown list. It looks like Ajax call never reaches controller's method GetMyList(). What is wrong with my code ? Thank you //in mypage.cshtml @model IEnumerable @{ ViewBag.Title = "MyPage"; Layout = "~/Views/Shared/_MyLayout.cshtml"; }

        ....

        Find

        @Html.Partial("_MyPartialView", Model) // displayed on initial page load

        ...

        @section MySection{ $('#btnGetList').on('click', function (event) { alert("go get list"); // shows up var myName = "Jo"; $.ajax({ type: "POST", url: "Main/GetMyList", data: myName, success: function (data) { alert("list is here"); //does Not show up $("#divWithPartialView").html(data); } }); alert("after ajax"); //shows up }) } // Controller namespace MyProject.Controllers { public class MainController: Controller { ............ [HttpGet] public ActionResult MyPage() { List myList = new List(); return View(myList); } public ActionResult GetMyList(string myName) { MyModel mm = new MyModel(); List myList = mm.GetNames(myName); // using search criteria entered on the previous Application page return PartialView("_MyPartialView", myList); } } } //Partial View: _MyPartialView.cshtml @model IEnumerable Select your name: - select name - @foreach (var name in Model) { @name.myName } //Model public class MyModel { public int id { get; private set; } public string myName { get; set; } public List GetNames(strin

        P Offline
        P Offline
        Pratik Bhuva
        wrote on last edited by
        #3

        Try...

        $.ajax({
        ...
        ...
        url: '@Url.Action("ActionName","ControllerName")',
        ...
        ...
        })

        Pratik Bhuva --------------- The night is darkest just before the dawn. And I promise you, the dawn is coming

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups