首页 > 解决方案 > 单击网页中的放大按钮或任何按钮时,它不会导航到详细信息页面

问题描述

在 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 餐厅内容的详细信息页面,但是当我单击放大按钮它不会导航到页面。

标签: htmlasp.netvisual-studio-2019

解决方案


改变asp-all-route-restaurantId="@restaurant.Id"

asp-route-restaurantId="@restaurant.Id"

-all-从标签中删除。


推荐阅读