Visual Studio 2017 (v15.4.4)
ASP.NET CORE MVC
代码来源:
@model Razor.Models.GuestResponse
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width"/>
<title>Index</title>
</head>
<body>
@ViewBag.Greeting World (from the view)
<p>We're going to have an excuting party.<br/>
(To do: sell it better. Add pictures or something.)</p>
<a asp-action="RsvpForm">RSVP Now.</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但asp-action属性并不创建href属性。我在 Google Chrome 中得到这样的结果:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width"/>
<title>Index</title>
<script type="text/javascript" src="http://gc.kis.v2.scr.kaspersky-labs.com/50E639F5-BFDC-EB4A-B0CB-8404EE08E366/main.js" charset="UTF-8"></script><link rel="stylesheet" crossorigin="anonymous" href="http://gc.kis.v2.scr.kaspersky-labs.com/663E80EE4048-BC0B-A4BE-CDFB-5F936E05/abn/main.css"/></head>
<body>
Good Afternoon World (from the view)
<p>We're going to have an excuting party.<br/>
(To do: sell it better. Add pictures or something.)</p>
<a asp-action="RsvpForm">RSVP Now.</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
造成这样结果的原因是什么?
在 View 上方使用这两行代码:
@model Razor.Models.GuestResponse
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, YourProjetcName
Run Code Online (Sandbox Code Playgroud)
如果添加这些代码后问题没有解决,请重新启动 Visual Studio。