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; }
}
记录
列表
. 一对多分贝:
我在打开
记录
从
列表
:
现在我想为一个
Record
看起来是这样的:
但是,要做到这一点,我需要正确传递多个参数:
ListId
和
RecordId
通过
csgtml
文件。像这样:
<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)
转到断点,但是,两个参数都为null,URL如下所示: