gpt4 book ai didi

asp.net-mvc - 在 asp.net mvc 选择列表上获取选定的值

转载 作者:行者123 更新时间:2023-12-02 00:38:14 25 4
gpt4 key购买 nike

我无法在 mvc 下拉列表中获取所选项目。我受不了viewdata,每个例子都用它。这是我的代码,提前致谢。

//controller
public ActionResult Register(Models.Person APerson)
{

}

public class Person
{
public Person()
{
using (var model = new theModel())
{

var countriesList = (from c in model.Countries
orderby c.Name ascending
select c).ToList();
Countries = new SelectList(countriesList, "ID", "Name");

}

}

[Required]
[DisplayName("Country")]
public SelectList Countries { get; set; }


public string SelectedCountry { get; set; }

}

<%=Html.DropDownListFor(m => m.SelectedCountry, Model.Countries) %>

我知道这方面有很多问题,但我找不到使用该模式的简单示例。

最佳答案

Countries.SelectedValue

关于asp.net-mvc - 在 asp.net mvc 选择列表上获取选定的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3712751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com