如何解决当单击放大按钮或网页中的任何按钮时,它不会导航到详细信息页面
在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();
}
} }
[这是详细信息模型的代码]
@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>
注意:当我像https://localhost:44040/Restaurants/Detail/1这样在网页上手动键入URL时,可以在其中看到包含ID为1的餐厅内容的详细信息页面,但是当我单击放大按钮时,不会导航到页面。
解决方法
更改asp-all-route-restaurantId="@restaurant.Id"
到asp-route-restaurantId="@restaurant.Id"
从标记中删除-all-
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。