これは私のVMです
public class CountriesViewModel
{
public string CurrentCountry { get; set; }
public IEnumerable<Country> Countries { get; set; }
}
私のコントローラーで
public class FiltersController : Controller
{
public ActionResult _ShipToCountry(IEnumerable<Country> countries,
string currentCountry = "AE")
{
var viewModel = new CountriesViewModel
{
Countries = countries.OrderBy(x => x.Name),
CurrentCountry = currentCountry
};
return PartialView(viewModel);
}
}
そして最後にビュー
@Html.DropDownListFor(x => x.Countries,
new SelectList(Model.Countries.ToList(),
"Code", "Name", Model.CurrentCountry))
ここで、Model.CurrentCountryはコードです。
DDLは正しくレンダリングされます
...
<option value="UA">Ukraine</option>
<option value="AE">United Arab Emirates</option>
<option value="UK">United Kingdom</option>
....
しかし、国は選択されません、私は何が欠けていますか?