【发布时间】:2021-05-09 09:25:33
【问题描述】:
这是查看部分中的代码:
<select name="country">
<option value="0">Select</option>
@foreach (var country in countries)
{
<option value="@country.CountryId"> @country.CountryName</option>
}
</select>
从控制器获取值的代码:
public ActionResult IndexPost()
{
ViewBag.Countries = CountryRepository.GetCountries();
if (Request["btnSubmitCountry"] != null)
{
string country = Request["country"];
ViewBag.Msg = "You have selected " + country;
}
return View();
我也想请求获取国家/地区名称的值,但现在它只获取 id。你能帮我用这个方法获取id和name吗?
【问题讨论】:
标签: c# html .net asp.net-mvc