Visual Studio 2017(v15.4.4)
ASP。NET Core MVC
我创建了新的ASP。NET核心Web应用程序从空模板中填充它。但当我开始调试时,我发现我的CSS文件无法访问。
找不到该网址的页面
http://localhost:51308/css/styles.css
HTTP错误404
为什么会发生这种情况?我如何解决这个问题?
样式。css
:
.field-validation-error {color: #f00;}
.field-validation-valid {display: none;}
.input-validation-error {border: 1px solid #f00; background-color: #fee;}
.validation-summary-errors {font-weight: bold; color: #f00;}
.validation-summary-valid {display: none;}
RsvpForm。cshtml
:
@model Razor.Models.GuestResponse
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Razor
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>RSVP Form</title>
<link rel="stylesheet" href="~/css/styles.css"/>
</head>
<body>
<div>
This is RSVP form.
<form asp-action="RsvpForm" method="post">
<div asp-validation-summary="All"></div>
<p>
<label asp-for="Name">Your name:</label>
<input asp-for="Name" />
</p>
<p>
<label asp-for="Email">Your email:</label>
<input asp-for="Email" />
</p>
<p>
<label asp-for="Phone">Your phone:</label>
<input asp-for="Phone" />
</p>
<p>
<label>Will you attend?</label>
<select asp-for="WillAttend">
<option value="">Choose an option</option>
<option value="true">Yes I'll be there</option>
<option value="false">No, I can't come</option>
</select>
</p>
<button type="submit">Submit RSVP</button>
</form>
</div>
</body>
</html>
UPD
我重命名了
styles.css
到
site.css
并在GitHub上分享了这个示例:
here
是此示例的代码源。