Practical 7
Practical 7
@page
@model FileUploadDemo.Pages.UploadModel
@{
ViewData["Title"] ="File Upload";
}
<h2>Upload a File</h2>
@if (!string.IsNullOrEmpty(Model.Message))
{
<div class="alert alert-info">@Model.Message</div>
}
namespace FileUploadDemo.Pages
{
public class UploadModel : PageModel
{
[BindProperty]
[Required]
public IFormFile UploadedFile {get; set; }
if (UploadedFile.Length >MaxFileSize)
{
Message ="File size exceeds the 5MB limit!";
return Page();
}
File: _Layout.cshtml
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>@ViewData["Title"] - My Application</title>
<link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
<header>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/About">About</a></li>
<li><a href="/Contact">Contact</a></li>
</ul>
</nav>
</header>
<main role="main" class="container">
@RenderBody()
</main>
<footer>
<p>© 2025 - My Application</p>
</footer>
<script src="~/js/site.js"></script>
</body>
</html>
Page: Index.cshtml
@page
@model IndexModel
@{
Layout ="_Layout";
ViewData["Title"] ="Home Page";
}
<h1>Welcome to My Application</h1>
<p>This is the home page.</p>
File: _ViewStart.cshtml
CSS: site.css
body {
font-family: Arial, sans-serif;
}
header {
background-color: #f8f9fa;
padding: 10px 0;
}
nav ul {
list-style-type: none;
padding: 0;
}
nav ul li {
display: inline;
margin-right: 10px;
}
footer {
text-align: center;
padding: 10px 0;
background-color: #f8f9fa;
}
JavaScript: site.js
Task 3: Theme and Navigation
To set up a theme, you typically need to work with CSS and possibly some
JavaScript. Here’s a basic example:
/* wwwroot/css/site.css */
body {
font-family: Arial, sans-serif;
background-color: #f8f9fa;
color: #333;
}
header {
background-color: #007bff;
color: white;
padding: 10px 0;
text-align: center;
}
nav {
margin: 10px 0;
}
nav a {
margin: 0 15px;
text-decoration: none;
color: #007bff;
}
nav a:hover {
text-decoration: underline;
}
2. Creating Navigation
Navigation is typically handled in the _Layout.cshtml file, as shown above. Here’s a
more detailed example:
If you need dynamic navigation based on user roles or other conditions, you can use
Razor syntax to conditionally render links:
Task 4:
Based on the GUI you have created before, apply the file upload, master page,
themes and navigation wherever possible/suitable.
Submission:
1. The project solution folder for all tasks.
2. The justification of the elements you applied for Task 4 and the screenshot of
the result in Ms. Word file.