OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

i want to pass all list after doing the post operation in Ajax

  • Thread starter Thread starter Rajat Bhandwalkar
  • Start date Start date
R

Rajat Bhandwalkar

Guest
***I am trying to pass a list from controller to ajax in success. Its a post request from ajax. *** When I am trying it comes as [model model]

*This my controller

Code:
public JsonResult CreatePackage(string Package)
{
    new ProductQueries().InsertTable("Packages", _DataBaseName, Package);
    List<Packages> packages = new ProductQueries().GetPackageTable("Packages", _DataBaseName);
   
    return Json(packages);
}

**This is my ajax please can someone let me know what I am doing wrong. Using after ages bit rusty on it any help is appreciated**


function CreatePackage() {
     var Package = $('#Package').val();
     $.ajax({
         type: 'POST',
         dataType: 'JSON',
         url: '@Url.Action("CreatePackage", "Product")',
         data: { Package },
         success:
             function (data) {
                 console.log(data);
                 debugger;
                 $.each(data, function (key, item) {
                     $("DropDownList").append('< label class="dropdown-option" ><input type="checkbox" name = "dropdown-group" value = "' + key+ '" />' + item+ '< /label>');
                 });
             }
     });
 }

**This is my model**
 public class Packages
 {
     public int Id { get; set; }
     public string Package { get; set; }
 }

<p>***I am trying to pass a list from controller to ajax in success. Its a post request from ajax. ***
When I am trying it comes as [model model]</p>
<p>*<strong>This my controller</strong></p>
<pre><code>public JsonResult CreatePackage(string Package)
{
new ProductQueries().InsertTable("Packages", _DataBaseName, Package);
List<Packages> packages = new ProductQueries().GetPackageTable("Packages", _DataBaseName);

return Json(packages);
}

**This is my ajax please can someone let me know what I am doing wrong. Using after ages bit rusty on it any help is appreciated**


function CreatePackage() {
var Package = $('#Package').val();
$.ajax({
type: 'POST',
dataType: 'JSON',
url: '@Url.Action("CreatePackage", "Product")',
data: { Package },
success:
function (data) {
console.log(data);
debugger;
$.each(data, function (key, item) {
$("DropDownList").append('< label class="dropdown-option" ><input type="checkbox" name = "dropdown-group" value = "' + key+ '" />' + item+ '< /label>');
});
}
});
}

**This is my model**
public class Packages
{
public int Id { get; set; }
public string Package { get; set; }
}
</code></pre>
 

Latest posts

Online statistics

Members online
0
Guests online
2
Total visitors
2
Ads by Eonads
Top