我有一个 MVC3 项目,它有一个这样的列表框(listboxfor):
@Html.ListBoxFor(m => m.cat_fam_codes, new SelectList(BaanWrapper.GetAllCategoryFamilies(), "Code", "Description"), new { @size = "10" })
测试时,我可以在列表中选择多个条目,甚至添加一个事件处理程序以在选择它们时弹出所选值的逗号限制列表。但是,当我将表单发布回控制器时,我只会返回第一个选定的值。例如,如果我选择值 1,2,3,4 - 我的 JQuery 事件处理程序将弹出“1,2,3,4”。没问题 - 但在回发时,控制器中引用的绑定对象仅显示“1”。
[HttpPost]
public ActionResult Create(EventReport eventReport)
{
return View(eventReport);
}
任何帮助将不胜感激。
编辑:
这是 EventReport 数据模型/类:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace EWS.Models
{
[MetadataType(typeof(EventReportMetaData))]
public partial class EventReport
{
private static readonly EWSDataContext db = new EWSDataContext();
#region Nested type: MetaData
private sealed class EventReportMetaData
{
[DisplayName("Alert Email Body")]
[Required(ErrorMessage = "Required")]
public string alert_body { get; set; }
[DisplayName("Alert Email Subject")]
[Required(ErrorMessage = "Required")]
public string alert_subject { get; set; }
[DisplayName("Categories")]
public string cat_codes { get; set; }
[DisplayName("Category Families")]
public string cat_fam_codes { get; set; }
[DisplayName("CCR Codes")]
public string ccr_codes { get; set; }
[Required(ErrorMessage = "Required")]
public DateTime create_dtm { get; set; }
[Required(ErrorMessage = "Required")]
public int created_by { get; set; }
[DisplayName("Email List")]
[Required(ErrorMessage = "Required")]
[IsInteger(ErrorMessage = "Invalid Email List")]
[IsGreaterThanZero(ErrorMessage = "Required")]
public int email_list_id { get; set; }
[DisplayName("Begin Date")]
public DateTime begin_dtm { get; set; }
[DisplayName("End Date")]
public DateTime end_dtm { get; set; }
[DisplayName("Event Threshold")]
[Required(ErrorMessage = "Required")]
[IsInteger(ErrorMessage = "Invalid Threshold")]
public int event_count { get; set; }
[DisplayName("Disabled")]
public bool is_disabled { get; set; }
[DisplayName("Notify Over Threshold")]
[Required(ErrorMessage = "Required")]
public bool notify_over_events { get; set; }
[DisplayName("Notify Under Threshold")]
[Required(ErrorMessage = "Required")]
public bool notify_under_events { get; set; }
[Required(ErrorMessage = "Required")]
public int report_id { get; set; }
[DisplayName("Report Title")]
[Required(ErrorMessage = "Required")]
public string report_title { get; set; }
[DisplayName("Reset By")]
public int reset_by { get; set; }
[DisplayName("Reset Date")]
public DateTime reset_dtm { get; set; }
[DisplayName("SKUs")]
public string skus { get; set; }
[DisplayName("Source System")]
[Required(ErrorMessage = "Required")]
public string source_system { get; set; }
[DisplayName("Sub-Categories")]
public string sub_cat_codes { get; set; }
[DisplayName("# of Time Units")]
[Required(ErrorMessage = "Required")]
public int window_dt_part_count { get; set; }
[DisplayName("Unit of Time")]
[Required(ErrorMessage = "Required")]
public string window_dt_part { get; set; }
}
#endregion
}
}
谢谢!