Asp.net mvc ASP.Net核心剃须刀页面-将所选名称从一个索引页面传递到另一个索引页面
我有一个项目,我正在ASP.NETCore中用Razor页面创建。这将跟踪我们的IT部门对Epicor ERP系统的开发项目。到目前为止,我在主页顶部有链接,可以打开相应的索引页面。这些页面从SQL Server表中提取数据。其中两个页面只有一列,其中包含元素名称列表,我希望能够单击其中任何一个名称,并将所选名称传递给另一个索引页面,该页面将仅显示该名称的项目。例如,这是我们在ERP系统中使用的UD表列表(参见下图) 我希望用户能够单击此列表中的任何名称,比如第一个名称“UD02”,并将该名称传递到第二个索引页(参见下图) 我知道您可以将asp路由id传递给详细信息、编辑和删除页面,但不确定如何将名称值传递给索引样式页面的For Each循环。我试着用类似的方式传递这个名字Asp.net mvc ASP.Net核心剃须刀页面-将所选名称从一个索引页面传递到另一个索引页面,asp.net-mvc,asp.net-core,razor-pages,Asp.net Mvc,Asp.net Core,Razor Pages,我有一个项目,我正在ASP.NETCore中用Razor页面创建。这将跟踪我们的IT部门对Epicor ERP系统的开发项目。到目前为止,我在主页顶部有链接,可以打开相应的索引页面。这些页面从SQL Server表中提取数据。其中两个页面只有一列,其中包含元素名称列表,我希望能够单击其中任何一个名称,并将所选名称传递给另一个索引页面,该页面将仅显示该名称的项目。例如,这是我们在ERP系统中使用的UD表列表(参见下图) 我希望用户能够单击此列表中的任何名称,比如第一个名称“UD02”,并将该名称
@page
@model EpicorDevInfo.Pages.UDTables.IndexModel
@{
ViewData["Title"] = "UD Tables";
}
<h1>UD Tables</h1>
<p>
<a asp-page="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.UDTable[0].TableName)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.UDTable.OrderBy(r => r.TableName))
{
<tr>
<td>
@*@Html.DisplayFor(modelItem => item.TableName)*@
<a asp-page="./Data/Data" asp-route-name="@item.TableName">@Html.DisplayFor(modelItem => item.TableName)</a>
</td>
<td>
<a asp-page="./Edit" asp-route-id="@item.ID">Edit</a> |
<a asp-page="./Details" asp-route-id="@item.ID">Details</a> |
<a asp-page="./Delete" asp-route-id="@item.ID">Delete</a>
</td>
</tr>
}
</tbody>
</table>
@page
@模型EpicorDevInfo.Pages.UDTables.IndexModel
@{
ViewData[“Title”]=“UD表”;
}
UD表
创造新的
@Html.DisplayNameFor(model=>model.UDTable[0].TableName)
@foreach(Model.UDTable.OrderBy(r=>r.TableName)中的var项)
{
@*@DisplayFor(modelItem=>item.TableName)*@
@DisplayFor(modelItem=>item.TableName)
编辑|
细节|
删除
}
我在第二个索引页的@页上添加了名称,但没有任何作用
@page "{name}"
@model EpicorDevInfo.Pages.UDTables.Data.IndexModel
@{
ViewData["Title"] = "Index";
}
<h1>@Html.DisplayFor(model => model.UDTableData[0].TableName)</h1>
<p>
<a asp-page="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.UDTableData[0].TableName)
</th>
<th>
@Html.DisplayNameFor(model => model.UDTableData[0].ColumnLabel)
</th>
<th>
@Html.DisplayNameFor(model => model.UDTableData[0].DatabaseColumn)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.UDTableData)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.TableName)
</td>
<td>
@Html.DisplayFor(modelItem => item.ColumnLabel)
</td>
<td>
@Html.DisplayFor(modelItem => item.DatabaseColumn)
</td>
<td>
<a asp-page="./Edit" asp-route-id="@item.ID">Edit</a> |
<a asp-page="./Details" asp-route-id="@item.ID">Details</a> |
<a asp-page="./Delete" asp-route-id="@item.ID">Delete</a>
</td>
</tr>
}
</tbody>
</table>
@page“{name}”
@模型EpicorDevInfo.Pages.UDTables.Data.IndexModel
@{
ViewData[“标题”]=“索引”;
}
@Html.DisplayFor(model=>model.UDTableData[0].TableName)
创造新的
@DisplayNameFor(model=>model.UDTableData[0].TableName)
@Html.DisplayNameFor(model=>model.UDTableData[0].ColumnLabel)
@DisplayNameFor(model=>model.UDTableData[0].DatabaseColumn)
@foreach(Model.UDTableData中的var项)
{
@DisplayFor(modelItem=>item.TableName)
@DisplayFor(modelItem=>item.ColumnLabel)
@DisplayFor(modelItem=>item.DatabaseColumn)
编辑|
细节|
删除
}
这是第二个索引页的C部分
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using EpicorDevInfo.Data;
using EpicorDevInfo.Models;
namespace EpicorDevInfo.Pages.UDTables.Data
{
public class DataModel : PageModel
{
private readonly EpicorDevInfo.Data.EpicorDevInfoContext _context;
public DataModel(EpicorDevInfo.Data.EpicorDevInfoContext context)
{
_context = context;
}
public IList<UDTableData> UDTableData { get; set; }
public async Task<IActionResult> OnGetAsync(string name)
{
if (String.IsNullOrEmpty(name))
{
return NotFound();
}
UDTableData = await _context.Epi_UDTableData_TEMP.ToListAsync();
if (UDTableData == null)
{
return NotFound();
}
return Page();
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Threading.Tasks;
使用Microsoft.AspNetCore.Mvc;
使用Microsoft.AspNetCore.Mvc.RazorPages;
使用Microsoft.EntityFrameworkCore;
使用EpicorDevInfo.数据;
使用EpicorDevInfo.Models;
命名空间EpicorDevInfo.Pages.UDTables.Data
{
公共类数据模型:PageModel
{
私有只读EpicorDevInfo.Data.EpicorDevInfo上下文\u上下文;
公共数据模型(EpicorDevInfo.Data.EpicorDevInfo上下文)
{
_上下文=上下文;
}
公共IList UDTableData{get;set;}
公共异步任务OnGetAsync(字符串名称)
{
if(String.IsNullOrEmpty(name))
{
返回NotFound();
}
UDTableData=Wait_context.Epi_UDTableData_TEMP.ToListSync();
if(UDTableData==null)
{
返回NotFound();
}
返回页();
}
}
}
我相信这很简单,但我还没有找到我想要的东西。任何帮助都将不胜感激。感谢您抽出时间,祝您度过愉快的一天 首先,如果我使用您的代码,我可以在DataModel的
OnGetAsync
中获取名称
然后你可以试着改变
UDTableData = await _context.Epi_UDTableData_TEMP.ToListAsync();
到
在OnGetAsync(字符串名称)
UDTableData = await _context.Epi_UDTableData_TEMP.Where(t=>t.TableName==name).ToListAsync();