html - 单击网页中的放大按钮或任何按钮时,它不会导航到详细信息页面
问题描述
在 Visual Studio2019 中,我使用 .net 2.1 构建了一个名为 OdeToFood 的项目,当我单击未导航到我想要的页面(详细信息页面)的网页上的缩放按钮时遇到问题,它保持当我点击这个缩放按钮时,在同一页面上,虽然我已经检查了几次代码,除了我不知道问题出在哪里。
[这里是缩放按钮的详细代码]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using OdeToFood.Core;
using OdeToFood.Data;
namespace OdeToFood.Pages.Restaurants
{
public class DetailModel : PageModel
{
private readonly IRestaurantData restaurantData;
[TempData]
public string Message { get; set; }
public Restaurant Restaurant { get; set; }
public DetailModel(IRestaurantData restaurantData)
{
this.restaurantData = restaurantData;
}
public IActionResult OnGet(int restaurantId)
{
Restaurant = restaurantData.GetById(restaurantId);
if (Restaurant == null)
{
return RedirectToPage("./NotFound");
}
return Page();
}
} }
[这里是Detail模型的代码]
@page "{restaurantId:int}"
@model OdeToFood.Pages.Restaurants.DetailModel
@{
ViewData["Title"] = "Detail";
}
<h2>@Model.Restaurant.Name</h2>
<div>
Id: @Model.Restaurant.Id
</div>
<div>
Location: @Model.Restaurant.Location
</div>
<div>
Cuisine: @Model.Restaurant.Cuisine
</div>
<a asp-page="./List" class="btn btn-default">All Restaurants</a>
[这里是放大餐厅列表的代码]
@page
@model OdeToFood.Pages.Restaurants.ListModel
@{
ViewData["Title"] = "Restaurants";
}
<h1>Restaurants</h1>
<form method="get">
<div class="form-group">
<div class="input-group">
<input type="search" class="form-control"
asp-for="SearchTerm" />
<span class="input-group-btn">
<button type="submit" value="" class="btn btn-default">
<i class="glyphicon glyphicon-search"></i>
</button>
</span>
</div>
</div>
</form>
<table class="table">
@foreach (var restaurant in Model.Restaurants)
{
<tr>
<td>@restaurant.Name</td>
<td>@restaurant.Location</td>
<td>@restaurant.Cuisine</td>
<td>
<a class="btn btn-lg"
asp-page="./Detail"
asp-all-route-restaurantId="@restaurant.Id">
<i class="glyphicon glyphicon-zoom-in"></i>
</a>
<a class="btn btn-lg"
asp-page="./Edit"
asp-all-route-restaurantId="@restaurant.Id">
<i class="glyphicon glyphicon-edit"></i>
</a>
</td>
</tr>
}
</table>
注意:当我在网页上手动键入 URL 时,例如https://localhost:44040/Restaurants/Detail/1,我可以在其中看到包含 Id=1 餐厅内容的详细信息页面,但是当我单击放大按钮它不会导航到页面。
解决方案
改变asp-all-route-restaurantId="@restaurant.Id"
到asp-route-restaurantId="@restaurant.Id"
-all-
从标签中删除。
推荐阅读
- php - 有什么办法可以防止owncloud内存不足?
- leaflet - 传单:更改默认标题长度
- json - Scala Play 中的空序列化(隐式写入)
- powershell - Passing PowerShell data variables to Terraform scripts
- cmd - cmd.exe 无法运行除内置命令外的任何命令
- python - 如何使用python同时多次运行python脚本并在完成后全部终止
- c - Capstone 不会反汇编过去的 INVALID 指令
- android - Flutter AWS:如何验证存储桶的 IAM 角色用户并获取 hls 视频文件的 AWS S3 对象并在视频播放器中播放?
- caching - Apache 点燃 REST API
- r - 基于 R 中动态列名的条件