Files
School/Anul 2/Semestrul 2/Web/Lab 9/Lab9/Views/View.cshtml
T
2024-08-31 12:07:21 +03:00

83 lines
3.5 KiB
Plaintext

@model IList<Lab9.Models.News>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
View
</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
</head>
<body>
<div class="container text-center">
<h3>Welcome</h3>
<div class='dropdown'>
<button class='btn btn-secondary dropdown-toggle' type='button' id='dropdownMenuButton'
data-bs-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>
Filter
</button>
<div class='dropdown-menu' aria-labelledby='dropdownMenuButton'>
<input class='dropdown-item' type="date" id="dateField" class="form-control" required>
<input class='dropdown-item' placeholder="Category" type="text" id="categoryField" class="form-control"
required>
<input class='dropdown-item' type="button" class="btn btn-primary" id="filterButton" value="Filter">
</div>
</div>
<table class="container" id="newsTable"
style="margin: 30px; border: 1px solid;border-color: black; border-collapse: collapse;">
<thead>
<tr>
<th>Title</th>
<th>Content</th>
<th>Category</th>
<th>Date</th>
<th>Producer</th>
</tr>
</thead>
<tbody id='tableBody'>
@foreach(var item in Model){
<tr>
<td>@item.Title </td>
<td>@item.NewsText </td>
<td>@item.Category </td>
<td>@item.Date.ToString("yyyy-MM-dd") </td>
<td>@item.Producer</td>
</tr>
}
</tbody>
<a class="btn btn-dark" name="backButton" href="/" style=" margin: 30px">Back</a>
</div>
<script>
$(document).ready(function () {
$('#filterButton').click(function () {
var date = $('#dateField').val();
var category = $('#categoryField').val();
$.ajax({
url: '/getnews',
type: 'POST',
data: {
date: date,
category: category,
},
success: function (response) {
$('#tableBody').empty();
for (var i = 0; i < response.length; i++) {
var newRow = "<tr><td>" + response[i].title + "</td><td>" + response[i].newsText +
"</td><td>" + response[i].category + "</td><td>" + response[i].date.slice(0,10) +
"</td><td>" + response[i].producer + "</td></tr>";
$('#tableBody').append(newRow);
}
}
});
});
});
</script>
</body>
</html>