當我通過點擊「btSave」發佈時,在控制器中我收到該模型。在模型中,我看到所有字段的值(我在這裏僅顯示「FirstName」,但也有其他字段)。但是,doropdownlist值始終爲空。ASP.NET MVC發佈一個下拉列表
你知道爲什麼嗎?
感謝,
//Dropfown content
public class LkpTypeCompany
{
public virtual int Id { get; set; }
public virtual int Code { get; set; }
public virtual string NL { get; set; }
public virtual string FR { get; set; }
public virtual string Value { get; set; }
}
//Model Definition
public class CustomerModel
{
public List<LkpTypeCompany> LkpTypeCompany { get; set; }
public Customer Customer { get; set; }
}
//Posting form
jQuery('#btGeneralSave').click(function (event) {
var jqxhr = $.post("Controller/Actio,", $("form").serialize(),
function (data) {
});
});
//HTML
@model eSIT.GC.WebUI.Models.CustomerModel
@using (Html.BeginForm())
{
@Html.TextBoxFor(m => m.Customer.FirstName, new { maxlength = 50 })
@Html.DropDownListFor(m => m.Customer.LkpTypeCompany, new SelectList(Model.LkpTypeCompany, "Code", "FR", Model.Customer.LkpTypeCompany.Code))
<input type="button" id="btSave" value="Save"/>
}
你不能DropDownListFor上使用屬性類型列表 http://msdn.microsoft.com/en-us/library/ee703436.aspx –
Omu
2011-06-07 02:07:35