【发布时间】:2019-03-12 18:56:57
【问题描述】:
我有剃须刀页面。 我在处理程序中准备了(visitorTypes)列表 我只想绑定它们。有些东西我错过了,但我不知道是什么
这是我的 C# 代码
[ModelBinder(Name ="Visitors")]
public ICollection<VisitorType> VisitorTypes { get; set; }
public IActionResult OnGetListOfVisitorTypeAsync()
{
VisitorTypes = _db.VisitorTypes.ToList();
return RedirectToPagePermanent("/Visitors",VisitorTypes);
}
这是我的剃须刀页面
<div class="container">
<form method="get" asp-page-handler="ListOfVisitorType" >
@foreach (var item in Model.VisitorTypes)
{
<label>@item.VisitorTypeName.ToString() </label>
}
</form>
</div>
谁能解释一下我做错了什么 (我试图返回列表,我试图使它成为一个 void 方法,但它们都不适合我)
这里是模态
private string _VisitorTypeName { get; set; }
public string VisitorTypeName { get {return _VisitorTypeName; } set { _VisitorTypeName = value; } }
ICollection<Visitor> Visitors { get; set; }
【问题讨论】:
-
你为什么使用
RedirectToPagePermanent? -
我不知道我还是新的,我认为它会再次加载以绑定数据
-
您可以添加您的
Model吗?在你的问题中 -
第一段C#代码在哪个页面?
-
@markdibe 请澄清您的具体问题或添加其他详细信息以准确突出您的需要。正如目前所写的那样,很难准确地说出你在问什么。请参阅How to Ask 页面以获得澄清此问题的帮助。它还缺少minimal reproducible example
标签: c# asp.net razor asp.net-core razor-pages