我想從表格中得到下拉列表。我有模式:ASPNET MVC中表格的下拉列表
namespace MobileService.Models
{
public class Mobile
{
public int Id { get; set; }
public string Model { get; set;}
Public string EMEI { get; set ;}
public int MasterId { get; set; }
public List<Master> MasterList { get; set; }
}
public class Master
{
public int Id { get; set; }
public string Name { get; set; }
}
}
在控制器我創造了這個模型行動:
public ActionResult Create()
{
return View();
}
鑑於:
@model MobileService.Models.Mobile
@using (Html.BeginForm()) {
@Html.EditorFor(model => model.Model)
@Html.EditorFor(model => model.EMEI)
// And here i want to display a drpodown list with all available masters
<button type="submit" class="btn btn-primary">Creat</button>
}
但它總是告訴我,Model.MasterList爲空。但爲什麼?在模型中,我告訴從另一個模型獲取列表(public List MasterList {get; set;})。爲什麼它是空的?
向我們展示您想要加載模型的控制器代碼.. – Oscar 2014-11-24 20:20:46
[C#MVC從下拉列表中獲取值](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF -8#q = C%23%20MVC%20get%20values%20 from%20dropdownlist)令人驚訝的是簡單的''GOOGLE SEARCH'可以產出' – MethodMan 2014-11-24 20:22:31
* Model.MasterList爲空。但是爲什麼?* - 你覺得它不會是什麼? – 2014-11-24 20:25:26