在这里,我正在使用下拉列表并收到类似的错误
ArgumentNullException was unhandled by user code
Value cannot be null.
Parameter name: items
收到此错误是因为在发布期间我获得了项目的空值。我已经在 MVC 中尝试过这个示例下拉 列表 这是我的下拉列表
@Html.DropDownListFor(m => m.SelectedItem, new SelectList(Model.Items, "Value", "Text")})
和我的模特
public class OptimizeModels
{
public string SelectedItem { get; set; }
public IEnumerable<Item> Items { get; set; }
}
public class Item
{
public string Value { get; set; }
public string Text { get; set; }
}
和我的控制器
public ActionResult Optimize()
{
var model = new OptimizeModels
{
Items = new[]
{
new Item { Value = "Sales", Text = "Units" },
new Item { Value = "RetGM", Text = "Rtlr Gross Margin ($)" },
new Item { Value = "MfrGM", Text = "Mfr Gross Margin ($)" },
}
};
return View(model);
}
[HttpPost]
public ActionResult Optimize(OptimizeModels model)
{
ObjOptimizeService = new OptimizeEventPerformance();
if (ModelState.IsValid)
{
ObjOptimizeInputParameter.ObjectivetoOptimize = model.SelectedItem;
model.ResponseXML = resultXMLContent;
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(resultXMLContent);
xdoc.Save(Server.MapPath("..\\XML_Files\\OutputXML.xml"));
}
model.ChartName = ObjCommon.GetFusionSWFReportName("Optimization", "OEP_3");
//return PartialView("../Home/RenderFusionChartView", model);
return View(model);
}
有什么建议吗?