ASP.NET CORE MVC:`asp-action`不会创建`href`属性

时间:2017-11-18 18:34:43

标签: asp.net-mvc razor

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>

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>

这种结果的原因是什么?

1 个答案:

答案 0 :(得分:2)

在视图上方使用以下两行代码:

@model Razor.Models.GuestResponse

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, YourProjetcName

如果在添加这些代码后问题仍未解决,请重新启动visual studio。