【发布时间】:2020-05-26 12:50:32
【问题描述】:
我正在注册城市,为此我想要一个国家下拉菜单。数据在控制器上正确显示,但之后显示错误。
这是我的代码“模型视图”
public class CountryCityViewModel
{
public int CountryId { get; set; }
public string name { get; set; }
public SelectList CountryList { get; set; }
public string CountryListId{ get; set; }
}
'城市控制器'
public async Task<IActionResult> Create()
{
var result = await _countryService.GetAllCountriesCity();
ViewBag.Cities = result;
return View(result);
}
'HTML'
<div class="form-group col-sm-6">
@Html.LabelFor(model => model.CountryId, "Country", htmlAttributes: new { @class = "control-label col-md-2" })
@Html.DropDownList(, new SelectList(ViewBag.Cities, "CountryId", "Name"))
@Html.ValidationMessageFor(model => model.CountryId, "", new { @class = "text-danger" })
</div>
'城市服务等级'
public async Task<IEnumerable<CountryCityViewModel>> GetAllCountriesCity()
{
var uri = $"{_siteConfiguration.ApiBaseUrl}{ApiEndPoint.Get_Countries_All}";
var response = _httpClient.GetAsync(uri).Result;
var contents = response.Content.ReadAsStringAsync().Result;
var result = JsonConvert.DeserializeObject<IEnumerable<CountryCityViewModel>>(contents);
return await Task.FromResult(result);
}
【问题讨论】:
-
那么...异常消息在哪里?
标签: c# html sql-server asp.net-mvc-3 .net-core