Reputation: 2764
I am attempting to create a simple web application using razor pages. The rendered anchor tag for Create
is not being generated correctly.
<a href>Create</a>
My application seems to not have /Facility/Create
as a valid URL even if I manually go there. Is there something else that I am suppose to be doing to get the anchor tag to render as
<a href="/Facility/Create">Create</a>
and for the application to know about /Facility/Create
.
@page
@model IndexModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<h1>Facilities</h1>
<form method="post">
<table class="table">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
@foreach (var facility in Model.Facilities)
{
<tr>
<td>@facility.Name</td>
<td>
<a asp-page="Edit" asp-route-id="@facility.Id">edit</a>
<button type="submit" asp-page-handler="delete"
asp-route-id="@facility.Id">
delete
</button>
</td>
</tr>
}
</tbody>
</table>
<a asp-page="/Facility/Create">Create</a>
</form>
Upvotes: 2
Views: 1073
Reputation: 247133
There is a tooling issue based on the IDE version being used, that may be corrupting the .csproj file.
The provided repo example has the following .csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<Folder Include="Pages\Facility\" />
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
In my research I came across the following
<Folder Include="..." />
just represents an empty folder inside the project. It doesn't include any file under the folder to the project.
In creating the folder the project added the node to the project file, but did not remove it after files were added. So the razor pages added under that folder were not being included at compile time and this caused the described issues at run time.
Suggest removing the node from the .csproj, as all files in the project folder are included/embedded/compiled by default unless specifically opted out in the project file.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
after recompiling the project, the missing pages will be available and provide the expected behavior.
Finally check to make sure that available patches and updates are applied to the IDE being used.
Upvotes: 1