MVC sql table data to html table

Multi tool use
MVC sql table data to html table
Hi guys i am new to mvc i am trying to get the sql table details to html table for that what i done is i have created a controller and model and view i also created sql table with fields of voucher number and amount. here is how i created the controller here i have referenced the model modeldemo
<HttpGet>
Function getVoucherDetails() As JsonResult
Return Json(New ModelDemo().getVoucherDetails(), JsonRequestBehavior.AllowGet)
End Function
the model demo code consists of sql connection
Public Function getVoucherDetails() As List(Of Hashtable)
Dim listCharts As List(Of Hashtable) = New List(Of Hashtable)
Dim arrayCharts As Hashtable
Try
Dim conn = New SqlConnection(connStringLocal)
conn.Open()
Using query = New SqlCommand("SELECT vchNum,totalAmount FROM BillHeader", conn)
Using resultSet = query.ExecuteReader
If resultSet.HasRows Then
While resultSet.Read()
arrayCharts = New Hashtable
arrayCharts.Add("vchNum", resultSet("vchNum"))
arrayCharts.Add("totalAmount", resultSet("totalAmount"))
listCharts.Add(arrayCharts)
End While
End If
resultSet.Close()
'resultSet = Nothing
End Using
End Using
conn.Close()
Catch ex As Exception
arrayCharts = New Hashtable
arrayCharts.Add("error", ex.ToString)
arrayCharts.Add("message", ex.Message)
listCharts.Add(arrayCharts)
End Try
Return listCharts
End Function
<table id="voucherTable">
<thead><tr> vchNum </tr><tr>Total Amount</tr></thead>
<tbody>
</tbody>
</table>
the document.load function consists of
$.post("@Url.Content("~")Home/SaveBill",$('#form1').serializeArray(),function(data){
console.log(data)
if (data.status == "success") {
alert(data.message)
$("# voucherTable >tbody").append('<tr><td><input name="vchNum"></td><td><input name="totalAmount"></td></tr>')
}
else {
alert("Error")
console.error(data.message)
}
});
and index html consists of
<table id="voucherTable">
<thead><tr> vchNum </tr><tr>Total Amount</tr></thead>
<tbody>
</tbody>
</table>
and this is how i tried can anyone help
1 Answer
1
There have space between #voucherTable
and Just try $("#voucherTable tbody").append
#voucherTable
$("#voucherTable tbody").append
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
i am wrong in script how do i get the details to html page
– Anburaj_N
Jul 2 at 8:16