Hi 65sametkaya65,
Refer below sample code.
Model
public class StockModel
{
public string ID { get; set; }
public string STOKADI { get; set; }
public string MIKTAR { get; set; }
public string FIYAT { get; set; }
public decimal TUTAR { get; set; }
}
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
List<StockModel> model = new List<StockModel>();
model.Add(new StockModel { ID = "1", STOKADI = "STOKADI 1", MIKTAR = "MIKTAR 1", FIYAT = "FIYAT 1", TUTAR = 500 });
model.Add(new StockModel { ID = "2", STOKADI = "STOKADI 2", MIKTAR = "MIKTAR 2", FIYAT = "FIYAT 2", TUTAR = 200 });
model.Add(new StockModel { ID = "3", STOKADI = "STOKADI 3", MIKTAR = "MIKTAR 3", FIYAT = "FIYAT 3", TUTAR = 150 });
return View(model);
}
}
HTML
@model IEnumerable<Sample_111368.Models.StockModel>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<a href="javascript:void(0)" onclick="PrintFunction('#printdiv')" class="btn btn-warning">Yazdır</a>
<div id="printdiv">
<table class="table table-bordered" style="margin-left: 20%; width: 50%">
<tr>
<th>Stok Adı</th>
<th>Miktar</th>
<th>Fiyat</th>
<th>Tutar</th>
<th>Sil</th>
</tr>
@foreach (var c in Model)
{
<tr>
<td>@c.STOKADI</td>
<td style="width: 150px">
<div class="item" style="">
<button style="background-color: black; color: #fff; border: none; float: left; width: 30px; height: 30px; font-size: 15px; border-radius: 50px" data-id="@c.ID" id="maz">-</button>
<input type="text" value="@c.ID" name="ID" id="txtid" hidden />
<input type="text" value="@c.MIKTAR" name="MIKTAR" id="txtmiktar" style="border: none; text-align: center; float: left; width: 30px; height: 30px; font-size: 15px" />
<button style="background-color: black; float: left; color: #fff; border: none; width: 30px; height: 30px; font-size: 15px; border-radius: 50px" data-id="@c.ID" id="mart">+</button>
</div>
</td>
<td>@c.FIYAT</td>
<td>@((System.Data.SqlTypes.SqlMoney?)c.TUTAR) ₺</td>
<td>
<div class="item">
<input type="text" name="ID" id="silid" value="@c.ID" hidden />
<button class="btn btn-danger" id="sil">Sil</button>
</div>
</td>
</tr>
}
</table>
</div>
<script>
$(document).ready(function () {
$('#printdiv').attr('style', 'display:none');
});
function PrintFunction(div) {
$(div).attr('style', 'display:block');
Popup($(div).html());
}
function Popup(data) {
var printwindow = window.open('', 'printdiv');
printwindow.document.write('<html><head><title></title>');
printwindow.document.write('</head><body>');
printwindow.document.write(data);
printwindow.document.write('</body><html>');
printwindow.document.close();
printwindow.focus();
printwindow.print();
printwindow.close();
$('#printdiv').attr('style', 'display:none');
}
</script>
</body>
</html>
Screenshot