0

I have a method in that I am having a date picker control, on that selection I want to bind the data to the same view.

So, I wanted to call non action method for onchange event of date using ajax(), but could not do it.

Can anyone help me with this?

[HttpGet]
    public ActionResult GetCall()
    {
        return View();
    }
[NonAction]
    public JsonResult GetData(int currentMonth)
    {
        var data= object.datacall(currentMonth);
        return Json(data, JsonRequestBehavior.AllowGet);
    }

ajax call:-

$.ajax({
    url: 'GetData',
    method: 'GET',
    data: { 'currentMonth': date.getMonth()},
    success: function (data) { },
    error: function (response) { }
});
Cleb
  • 25,102
  • 20
  • 116
  • 151
karun
  • 66
  • 8
  • Remove the `[NonAction]` attribute –  Jul 20 '18 at 06:09
  • Also read [this](https://stackoverflow.com/questions/6385599/asp-net-mvc-nonaction-meaning) to understand usage of `NonActionAttribute`. – Tetsuya Yamamoto Jul 20 '18 at 06:25
  • yes i can call it by removing [NonAction], but now it is invocable from URL – karun Jul 20 '18 at 07:00
  • 1
    Then use an [AjaxOnly](https://stackoverflow.com/questions/23900411/mvc-set-accessibility-level-on-a-method-called-from-ajax/23900475#23900475) attribute. –  Jul 20 '18 at 07:04
  • Yes that sounds good, thank you @StephenMuecke – karun Jul 20 '18 at 07:34

0 Answers0