这里我使用XML来加载我的下拉值。在从XML加载这些下拉值后,在HTTPPost中,所有其他模型值变为null,我的模型只有这些下拉值。
[HttpPost]
public ActionResult Analyze(AnalyzeModels model)
{
if (ModelState.IsValid)
{
model.RequestID = ObjCommon.GenerateRequsetID(ObjSharedEntities.UserID, "ATA_1"); // Generation of the Request ID
}
model.ChartName = ObjCommon.GetFusionSWFReportName("ASTrend", "ATA_1");
var ppgFile = Server.MapPath(DataTemplate.PPGXmlPath);
var ppgItems =
from brand in XDocument.Load(ppgFile).Descendants("PPGItem")
select new SelectListItem
{
Value = brand.Element("Value").Value,
Text = brand.Element("Text").Value
};
model = new AnalyzeModels
{
PPGItems = ppgItems
};
return View(model);
}
有什么建议吗?
答案 0 :(得分:1)
在您的代码中:
model = new AnalyzeModels
{
PPGItems = ppgItems
};
您正在创建模型的新实例,这将有效地清除您设置的值。
请考虑这样做:
model.PPGItems = ppgItems