已删除已删除已删除已删除已删除已删除已删除已删除已删除已删除已删除已删除已删除已删除已删除
您可以按如下方式实现
SelectList
List<string> wifiNetworks = new [] { "Local Network", "Customer Network" };
LocalWifis = wifiNetworks.Select(x => new SelectListItem()
{
Text = x,
Value = x,
Selected = x == "Local Network"
});
最后记得绑定你的属性。
[BindProperty]
public SelectList LocalWifis { get; set; }
或者您可以选择使用
ViewData
属性装饰它们,并在视图中访问它们,例如 @ViewData["LocalWifis"]
。
[ViewData]
public SelectList LocalWifis { get; set; }
更新:
您可以按如下方式实施:
using System.Collections.Generic;
using System.Linq;
public class RobotSshModel : PageModel
{
[BindProperty]
public string SelectedLocalWifi { get; set; }
[BindProperty]
public string SelectedCustomerWifi { get; set; }
[ViewData]
public SelectList LocalWifis { set; get; }
[ViewData]
public SelectList CustomerWifis { set; get; }
public void OnGet()
{
GetNetworks();
}
public void GetNetworks()
{
List<string> wifiNetworks = new List<string>() { "Local Network", "Customer Network" };
CustomerWifis = LocalWifis = wifiNetworks.Select(x => new SelectListItem()
{
Text = x,
Value = x,
Selected = x == "Local Network"
});
}
}
然后在 View 中调用:
@page
@model RobotSshModel
@Html.DropDownListFor(m => m.SelectedLocalWifi, Model.LocalWifis)
@Html.DropDownListFor(m => m.SelectedCustomerWifi, Model.CustomerWifis)