I'm getting error message when I add data annotation on upload file.
It give me error on asp-validation-for="fileUpload"
See code:
public class Customer {
public int CustomerId { get; set; }
public string Name { get; set; }
public string Country { get; set; }
[Required(ErrorMessage = "{0} is required.")]
public string fileUpload { get; set; }
}
@addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers
@using NADMIS.Models;
@model List<Customer>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<form method="post" asp-controller="Home" asp-action="Index" enctype="multipart/form-data">
<input type="file" asp-validation-for="fileUpload" name="postedFile" accept=".xlsx">
<span asp-validation-for="fileUpload" class="text-red"></span>
<input type="submit" value="Upload" />
</form>
<hr />
@if (Model != null)
{
<table cellpadding="0" cellspacing="0">
<tr>
<th>Id</th>
<th>Name</th>
<th>Country</th>
</tr>
@foreach (Customer customer in Model)
{
<tr>
<td>@customer.CustomerId</td>
<td>@customer.Name</td>
<td>@customer.Country</td>
</tr>
}
</table>
}
</body>
</html>