<pre>using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using System.Data.SqlClient; namespace MyStore.Pages.Porezi { public class IndexModel : PageModel { public List<ClientInfo> listClients = new List<ClientInfo>(); public void OnGet() { try { String connectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=test;Integrated Security=True;Trust Server Certificate=True"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); String sql = "SELECT * FROM porezi"; using (SqlCommand command = new SqlCommand(sql, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ClientInfo clientInfo = new ClientInfo(); clientInfo.id = "" + reader.GetInt32(0); clientInfo.redni_broj = reader.GetString(1); clientInfo.naziv = reader.GetString(2); clientInfo.procenat= "" + reader.GetString(3); clientInfo.fiksna_vrednost = "" + reader.GetString(4); clientInfo.oznaka = reader.GetString(5); listClients.Add(clientInfo); } } } } } catch (Exception ex) { Console.WriteLine("Exception: " + ex.ToString()); } } public class ClientInfo { public String id; public String redni_broj; public String naziv; public String procenat; public String fiksna_vrednost; public String oznaka; } } }
<pre>@page @model MyStore.Pages.Porezi.IndexModel @{ } <br> <h2>List of Clients</h2> <a class='btn btn-primary btn-sm' href='/Porezi/Create'>New Client </a> <table class="table"> <thead> <tr> <th>id</th> <th>redni_broj</th> <th>naziv</th> <th>procenat</th> <th>fiksna_vrednost</th> <th>oznaka</th> <th>Action</th> </tr> </thead> <tbody> @foreach(var item in Model.listClients) { <tr> <td>@item.id</td> <td>@item.redni_broj</td> <td>@item.naziv</td> <td>@item.procenat</td> <td>@item.fiksna_vrednost</td> <td>@item.oznaka</td> <td> <a class="btn btn-primary btn-sm" href="/Porezi/Edit?id=@item.id">Edit</a> <a class="btn btn-danger btn-sm" href="/Porezi/Delete?id=@item.id">Delete</a> </td> </tr> } </tbody> </table>
catch
listClients
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)