DataTable server side processing not working in .net 2.0
I have a JQuery Datatable (server side processing) working in .Net 4.5 but the same code is not working in .Net 2.0.
Due to specific requirements, i need to implement this in net 2.0 .
I get the following Internal Server Error 500 error message;
Here is the code to initialise DataTable
$('#tblDetails').DataTable({
"processing": true,
"serverSide": true,
"pageLength": 400,
"bDestroy": true,
"scrollY": "300px",
"scrollCollapse": true,
"ajax": {
url: "Service.asmx/GetDataForDataTable", type: "post",
data: function (d) {
d.regDate = registration_date,
d.Salary = salary;
}
},
"columns": [
{ "data": "Name" },
{ "data": "Date" },
]
});
Here is the DataTable response call;
public class DataTableResponse
{
public int draw;
public int recordsTotal;
public int recordsFiltered;
public List<SampleDetails> data;
}
If i pass the parameters in the following format then there is no error but server side method is not being called and datatable is stuck on processing.
data: "{ regDate: '" + registration_date + "', Salary: '" + salary + "'}",
See also questions close to this topic
-
getting prob on reading nested class c#
Hi really need assistance here,
I have 2 classes which i use to read from json i need to save into 2 tables (root and participants) in 1 submission. i will have only 1 root with 1 or many participants. i have no prob saving the root but i have prob reading if i am sending both (root with participants}
[ { "NoIC": "122233243", "Nama": "TEST NAME", ... "Participant": [ { "Nama" : "Participant 1", "Bil" : "1", ... }, { "Nama" : "Participant 2", "Bil" : "1", .... } ] } ] public class Participant { public string ref_no { get; set; } public string Nama { get; set; } public string Bil { get; set; } public string Price { get; set; } public string RequestedPlace { get; set; } public string RequestedExe { get; set; } public string RequestedDate { get; set; } public string Type { get; set; } } public class Root { public string NoIC { get; set; } public string Nama { get; set; } public string HPNo { get; set; } public string Email { get; set; } public string Type { get; set; } public string RegisterBy { get; set; } public List<Participant> Participant { get; set; } } public string RegisterApplication([FromBody] Root register, Participant participants) { try { using (MySqlConnection sql = new MySqlConnection(_connectionString)) { using (MySqlCommand cmd = new MySqlCommand("GetInsertApplication", sql)) { sql.Open(); cmd.CommandType = System.Data.CommandType.StoredProcedure; // cmd.Parameters.AddWithValue("@refNo", register.RefNo); cmd.Parameters.AddWithValue("@NoIC", register.NoIC); cmd.Parameters.AddWithValue("@Nama", register.Nama.ToUpper()); cmd.Parameters.AddWithValue("@NoFonHp", register.HPNo); cmd.Parameters.AddWithValue("@Email", register.Email); cmd.Parameters.AddWithValue("@refType", register.Type); cmd.Parameters.AddWithValue("@RegisterBy", register.RegisterBy); ...... ref_no = refnoParameter.Value.ToString(); //will pass this refno to child/participant
my prob is here. i need to read the child (1 Root can have more than 1 participant)
List<Participant> participants = new List<Participant>(); using (MySqlCommand cmd2 = new MySqlCommand("GetInsertParticipant", sql)) { cmd2.Parameters.AddWithValue("@ref_no", ref_no); cmd2.Parameters.AddWithValue("@Nama", participant.Nama.ToUpper()); cmd2.Parameters.AddWithValue("@Bil", participant.Bil); cmd2.Parameters.AddWithValue("@Price", participant.Price); cmd2.Parameters.AddWithValue("@RequestedPlace", participant.RequestedPlace); cmd2.Parameters.AddWithValue("@RequestedExe", participant.RequestedExe); cmd2.Parameters.AddWithValue("@RequestedDate", participant.RequestedDate); cmd2.Parameters.AddWithValue("@Type", participant.Type); cmd2.Connection.Open(); cmd2.CommandType = CommandType.Text; cmd2.ExecuteNonQuery();
}}}}}
anybody please, i stuck here for few days and i really need your help/opinion. thaks in advanced
-
How do I insert input from form to database?
My model looks like this:
public class Customer { public int CustomerId { get; set; } [Required(ErrorMessage = "Please enter a valid first name")] public string FirstName { get; set; } [Required(ErrorMessage = "Please enter a valid last name")] public string LastName { get; set; } [Required(ErrorMessage = "Please enter a valid address")] public string Address { get; set; } public string Email { get; set; } [Required(ErrorMessage = "Please enter a valid city")] public string City { get; set; } public string Phone { get; set; } [Range(1, 5, ErrorMessage = "Please enter a valid country")] public int CountryId { get; set; } public Country Country { get; set; } [Required(ErrorMessage = "Please enter a valid state")] public string State { get; set; } [Required(ErrorMessage = "Please enter a valid postal code")] public string PostalCode { get; set; } public string fullname => FirstName + LastName; }
My controller looks like this:
public class CustomerController : Controller { private CustomerContext context { get; set; } public CustomerController(CustomerContext ctx) { context = ctx; } public IActionResult List() { var customers = context.Customers.ToList(); return View(customers); } [HttpGet] public IActionResult Add() { ViewBag.Action = "Add"; ViewBag.Countries = context.Countries.OrderBy(c => c.Name).ToList(); return View("Edit", new Customer()); } [HttpGet] public IActionResult Edit(int id) { ViewBag.Action = "Edit"; ViewBag.Countries = context.Countries.OrderBy(c => c.Name).ToList(); var customer = context.Customers .Include(c => c.Country) .FirstOrDefault(c => c.CustomerId == id); return View(customer); } [HttpPost] public IActionResult Edit(Customer customer) { string action = (customer.CustomerId == 0) ? "Add" : "Edit"; if (ModelState.IsValid) { if (action == "Add") { context.Customers.Add(customer); } else { context.Customers.Update(customer); } context.SaveChanges(); return RedirectToAction("List", "Customer"); } else { ViewBag.Action = action; ViewBag.Countries = context.Countries.OrderBy(c => c.Name).ToList(); return View(customer); } }
I also have a DbContext file with data i created to test other things:
public class CustomerContext : DbContext { public CustomerContext(DbContextOptions<CustomerContext> options) :base(options) { } public DbSet<Customer> Customers { get; set; } public DbSet<Country> Countries { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Country>().HasData( new Country { CountryId = 1, Name = "Canada"}, new Country { CountryId = 2, Name = "United States"}, new Country { CountryId = 3, Name = "United Kingdom" }, new Country { CountryId = 4, Name = "Mexico" }, new Country { CountryId = 5, Name = "Russia" } ); modelBuilder.Entity<Customer>().HasData( new Customer { CustomerId = 1, FirstName = "Bruce", LastName = "Wayne", Phone = "416-123-4567", Email = "bruce.wayne@gmail.com", CountryId = 1, Address = "123 sesame street", City = "Toronto", PostalCode = "L812A", State = "Ontario" } ); }
I already did the add-migration and updated my database via the package manager console. I created a form in the view that looks like this:
Cancel<form method="post" asp-action="Add"> <div asp-validation-summary="All"> <div> <label asp-for="FirstName">First Name</label> <input type="text" name="FirstName" asp-for="FirstName" /> </div> <div> <label asp-for="LastName">Last Name</label> <input type="text" name="LastName" asp-for="LastName" /> </div> <div> <label asp-for="Address">Address</label> <input type="text" name="Address" asp-for="Address" /> </div> <div> <label asp-for="City">City</label> <input type="text" name="City" asp-for="City" /> </div> <div> <label asp-for="State">State</label> <input type="text" name="State" asp-for="State" /> </div> <div> <label asp-for="PostalCode">Postal Code</label> <input type="text" name="Postal Code" asp-for="PostalCode" /> </div> <div> <label asp-for="CountryId">Country</label> <select name="Country" asp-for="CountryId"> @foreach (Country country in ViewBag.Countries) { <option value="@country.CountryId">@country.Name</option> } </select> </div> <div> <label asp-for="Email">Email</label> <input type="text" name="Email" asp-for="Email" /> </div> <div> <label asp-for="Phone">Phone</label> <input type="text" name="Phone" asp-for="Phone" /> </div> <input type="hidden" asp-for="CustomerId" /> </div> <button type="submit" value="Save" asp-controller="Customer" asp-action="List">Save</button>
I've tried looking up multiple different solutions to solve my issue but I cant seem to figure out how to solve it. If someone could help me that would be much appreciated. thanks in advance.
-
Submit button doenst work with script asp.net mvc5
I have a maybe simple problem but I don`t have that much experience with scripts:
I have this Skript in my _Layout.cshtml:
<script> $('button').click(function () { $(this).prop('disabled', true); }); </script>
and one of my views:
@using (Html.BeginForm("Create", "Home", FormMethod.Post, null)) { @Html.AntiForgeryToken() <div class="mt-5 d-flex flex-row"> <textarea class="form-control" name="TextArea"></textarea> <button class="btn btn-secondary btn-block mt-2 post-btn" type="submit" id="PostButton">Post</button> </div> }
This form works great without the script, but for any reason with the script it doesn`t work.
I placed the script in the _layout.cshtml because I want to have it for all buttons in my asp.net page.
After click on the button the button is disabled - as I wish - but the action result "Create" in the HomeController will not called.
I think I need to extend the script but can someone help me how to do it?
Thanks all
-
How to get unique data from response of array and to redirect using react js?
class App extends React.Component { constructor(){ super(); this.state = { showItems:[], users: [] } } onClick(index){ console.log('its clicked') let showItems = this.state.showItems.slice(0); showItems[index] = !showItems[index]; this.setState({showItems}); axios .get("https://jsonplaceholder.typicode.com/users") .then(response => { console.log(response); this.setState({ users: response.data }); }) .catch(error => { console.log(Error); this.setState({ errorMsg: "Wrong API call !!!" }); }); } handleNest(event){ event.stopPropagation() console.log('i got a click') } render() { const { users } = this.state; return ( <div className="App"> <ul> <li onClick={this.onClick.bind(this,0)}> item {this.state.showItems[0] ? <div> {users.length ? users.map(user => ( <div style={{ padding: "10px", color: "blue", textTransform: "initial" }} onClick={this.handleNest.bind(this,i)} key={user.id} > {user.name} </div> )) : null} </div> : null} </li> </ul> <div style={{marginTop: 100}}>*click on item to open submenu</div> </div> );}} export default App;
MY Question is :
i want to get the one data which is getting click from that array, like i want to go to some other page with the data selected from array.
Attached image -- Here is the output of above code inside of item.. i can get the console by getting click, but i have to know which item is getting click and i have to fetch that for some other page, can anyone help me by suggesting any ideas please ....
-
how to test range age in postman
pm.test("Age for apply a job", function () { var jsonData = pm.response.json(); pm.expect(jsonData.resume.age).to.eql(jsonData.jobPosting.lowerBoundAge && jsonData.jobPosting.upperBoundAge); });
I want to test ages between 25-40 but this code can test the only age
jsonData.resume.age = 24
jsonData.jobPosting.lowerBoundAge = 25
jsonData.jobPosting.upperBoundAge = 40
-
windows hosts file website redirection using IIS
I wanted to redirect a website.
example 222.222.222.222 google.com
but when i do this with my own ip vps where i hosted the web, it says the site can't be reached when i connect to the real IP of the website hosted is up and online
This is the real website is up and working
-
How to set a GitHub origin and push commits through LibGit2Sharp to a private repo?
I'm working on a project right now that is basically a manager for a shared private repo for non-programmers.
I've got the authorization part working, and the local repo working as well, but I'm having a hard time figuring out how to connect the two dots. I'm still new to .NET and I'm finding the LibGit2Sharp docs hard to navigate.
What I need is, through my C# code, do a
git remote add origin
and agit push origin main
.How can I accomplish this?
-
How can I read an dynamic object from Microsoft.Extensions.Configuration.IConfiguration
I using .net core 3.1.
I have a json setting in appsetting.json:
{ "genericObject":{ "A": [ "B", "C"], "D": [ "ABC", "CCC"] } }
I have loaded the appsetting.json file to
Microsoft.Extensions.Configuration.IConfiguration
.How can I load an
object
instance from theIConfiguration
? I tried_Configuration.GetSection("genericObject").Get<object>(); _Configuration.GetValue<object>("genericObject")
Both failed. I don't want to create a class to load the json settings since it may change.
-
Does NReco.PivotData work with .NET Framework 4?
I want to download NReco.PivotData library would this work with .NETFramework 4.0? I am new to c# trying to understand what they mean by .NETFramework4.5 No dependencies.
-
Ajax form submit I want to change the value of a form element by id for the next call by the script from return value in php
I need to have the response from php update the html form element by id. I'm using Ajax to submit the form, and upon success it needs to change the value of the html element by ID. How can I make this work? Because right now it does nothing!
$.ajax({ url:"autosave.php?save=true", method:"POST", data:{"subject":subject,"body":body}, dataType:"text", success:function(data) { // $('#id').value = this.responseText; document.getElementsByName('id')[0].value = this.responseText; $('#autoSave').text("Updated"); } });
-
POST http://localhost:3000/post/vote 500 (Internal Server Error) - No route matches [GET] "/post/vote" when trying to post ajax in Rails
I am working with the voting button and try to post the ajax in RoR but cannot get through it.
Kindly check my route controller and the ajax as follows:
post 'post/vote' => 'votes#create'
class VotesController < ApplicationController def create vote = Vote.new post_id = params[:post_id] vote.post_id = params[:post_id] vote.account_id = current_account.id existing_vote = Vote.where(account_id: current_account.id, post_id: post_id) respond_to do |format| format.js do if existing_vote.size > 0 existing_vote.first.destroy else @success = if vote.save true else false end @post = Post.find(post_id) @total_upvotes = @post.upvotes @total_downvotes = @post.downvotes end end end end
$(function () { $(".vote").on("click", ".upvote", function () { let post_id = $(this).parent().data("id"); console.log("clicked " + post_id); $.ajax({ url: "post/vote", type:'POST', data: { post_id: post_id }, success: function(){ console.log("success"); } }); }); });
NoMethodError (undefined method `id' for nil:NilClass): app/controllers/votes_controller.rb:6:in `create' Started POST "/post/vote" for ::1 at 2021-02-27 12:58:29 +0700 Processing by VotesController#create as */* Parameters: {"post_id"=>"2"} Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.0ms | Allocations: 1234) NoMethodError (undefined method `id' for nil:NilClass): app/controllers/votes_controller.rb:6:in `create'
What I want at this point is to log the "success" why the error POST http://localhost:3000/post/vote 500 (Internal Server Error) appears and when I try to go to the http://localhost:3000/post/vote it shows No route matches [GET] "/post/vote" when trying to post ajax.
-
How to fetch specific data from database to show in datatable?
I want to implement the thing where I can be able to show only some specific data from database on the datatable. I had created an entity named User. In this model, I am storing the compound data i.e. in this entity I have records of customers and sales executive, sales manager etc. So, I want to display only sales executive and sales manager data on the datatable. I have did this way, but on the datatable, it is showing my all data i.e. including customer data also. So, how should I prevent this thing?
<c:forEach items="${userlist}" var="user"> <tr> <td>${user.userid}</td> <td>${user.salesuser}</td> <td>${user.phone}</td> <td>${user.email}</td> <td>${user.usertype}</td> <td>${user.createddatetime}</td> </tr> </c:forEach>
-
How can i use "lengthMenu: [10, 25, 50]," in if else correctly?
I need define 2 different config line about datatable by if else but my lines not working. I need a hand.
if(role === 1) { lengthMenu: [10, 25, 50], } else { lengthMenu: [10, 25, 50, 75, 100], }
-
Update DataTable based on new object data
I'm having some problems updating a datatable with new values. Currently, I am calling an API that returns columns and rows for a particular query. I then feed that information into the datatable (see below).
Example:
select * from parms
{columns: Array(4), data: Array(3)}
4 columns and 3 rows returned from the query. I now feed that into the data and columns property of the datatable (below).
<table class="table table-sm table-bordered table-striped bg-white" id="QueryResults"></table>
$('#QueryResults').dataTable({ dom:'l<Bf<t>ip>', lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]], destroy: true, "data": dataObject.data, "columns": dataObject.columns });
The following table is then produced.
This is all good if it's the initial query upon instantiation. However, every subsequent query that has a different number of columns doesn't show properly or the datatable doesn't work.
So let's say I selected * from this table, but now I only want to see PARMID.
select parmid from parms
Now executing this query after having done the one above, displays the table as seen below:
Even though the query only returned one column:
{columns: Array(1), data: Array(3)}
I do believe that I have to destroy the table before creating a new one. But after I do, I can no longer create a table since the div has been removed from the DOM. Being able to do this with datatables should be pretty easy, but I can't find what I'm looking for on their documentation site. I'd like the datatables to update automatically based on the new data that has been returned from the API call.
I can't pin-point what I'm doing wrong. Any help would be appreciated.
Thanks!
-
Row deselection issue using Datatables
Description of problem:
So just for some context, I am building a bioinformatic web app within python/flask, I dont have extensive knowledge using JS and this is the first time I have been experimenting with it so bare with me.I am trying to build an array of accession numbers (GSMxxxxxxx) based on the rows in the table that are currently highlighted. I have got to a point where I have tried different jquery methods in place of the original code, but I cant seem to get it the behave how I want it to.
The issue is when I deselect a row that I dont want to be in the array anymore (e.g. I miss click a row and want to un-highlight it), the entire array gets removed and not just the accession number that is contained in the row that I deselected.
I know how it could be done theoretically, I just dont have the requisite knowledge in JS to apply the logic into language - If the array only contained accession numbers that are from rows that are currently highlighted in the table, rather than on selection, I think that would solve my problem. Although I have tried using words such as "highlight(ed)" in place of "(de)select(ed)" to no avail.
Link to test case:
Test CasePlease let me know if there any issues with the test case or how I have constructed my question and I will try to help.
Thank you Benjamin