【发布时间】:2019-03-24 20:01:48
【问题描述】:
我从事 Razor Page 项目,该项目代表模型 Lists 和 Records:
public class List
{
public int ID { get; set; }
[StringLength(25, MinimumLength = 3, ErrorMessage = "Title should be in range between 3 and 25")]
[Display(Name = "Title")]
public string Caption { get; set; }
public string UserId { get; set; }
public User User { get; set; }
public ICollection<Record> Records { get; set; }
}
public class Record
{
public int ID { get; set; }
[StringLength(25, MinimumLength = 3, ErrorMessage = "Word should be in range between 3 and 25")]
[Display(Name = "Title")]
public string Word { get; set; }
[StringLength(30, MinimumLength = 3, ErrorMessage = "Translation should be in range between 3 and 30")]
public string Translation { get; set; }
public int ListId { get; set; }
public List List { get; set; }
}
我在从Lists 打开Records 列表时构建了有效的网址:
现在我想为单个 Record 构建类似的 URL,如下所示:
但是,要做到这一点,我需要通过csgtml 文件正确传递多个参数:ListId 和RecordId。像这样的:
<a asp-page="./Details" asp-route-id="@item.ID,@item.ListId">Details</a>
记录/详细信息(我要导航的页面)中方法 OnGetAsync 的签名应如下所示:
public async Task<IActionResult> OnGetAsync(int? id, int? listId) {...}
Records/Details.cshtml 中的页面定义应如下所示:
@page "/Lists/{listId}/Records/{id}/Details/"
但它不起作用!
如果我这样定义@page Records/Details.cshtml:
@page "/Lists/{id}/Records/Details/"
方法
public async Task<IActionResult> OnGetAsync(int? id, int? listId)
【问题讨论】:
标签: c# asp.net-core razor-pages