我的ajax表单有问题: 我有这个代码
@using (Ajax.BeginForm("Search", "SyntheseEvt",
FormMethod.Post,
new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
UpdateTargetId = "search-results"
}
))
{
<div class="row">
@{
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
<div class="col-md-4">
<div class="dx-field-label">@Resources.Resource.DDebut</div>
<div class="dx-field-value">
@(Html.DevExtreme().DateBox()
.ID("DtDebut")
.Type(DateBoxType.Date)
.Value(Model.paramSynthese.DtDebut_c)
.DisplayFormat(currentCulture.DateTimeFormat.ShortDatePattern)
)
使用该模型
public class SearchSyntheseEvtViewModel
{
public C_DAL_TRS_ATELIER DAL_TRS_ATELIER_c;
public List<C_BEL_TRS_ATELIER> ListBEL_TRS_ATELIER_c;
public C_DAL_TRS_MACHINE DAL_TRS_MACHINE_c;
public List<C_BEL_TRS_MACHINE> ListBEL_TRS_MACHINE;
public ParamSyntheseEvtViewModel paramSynthese;
public SearchSyntheseEvtViewModel()
{
}
public SearchSyntheseEvtViewModel Initialiser()
{
this.DAL_TRS_ATELIER_c = new C_DAL_TRS_ATELIER(C_Interface_Meta.Mesbdd_p, C_Interface_Meta.IndexBdd_p);
this.DAL_TRS_MACHINE_c = new C_DAL_TRS_MACHINE(C_Interface_Meta.Mesbdd_p, C_Interface_Meta.IndexBdd_p);
paramSynthese = new ParamSyntheseEvtViewModel();
paramSynthese = paramSynthese.Initialiser();
paramSynthese = paramSynthese.Charger();
return this;
}
public SearchSyntheseEvtViewModel Charger()
{
DAL_TRS_ATELIER_c.Charger(ref ListBEL_TRS_ATELIER_c);
DAL_TRS_MACHINE_c.Charger(ref ListBEL_TRS_MACHINE);
return this;
}
}
public class ParamSyntheseEvtViewModel
{
public string AT_ID_c { get; set; }
public string TR_ID_c { get; set; }
public DateTime DtDebut_c;
public DateTime DtFin_c;
public Metaproductique.Kmprod.Km_Synthese_Moteur.C_SyntheseEvenement Moteur_c { get; set; }
public List<string> MA_ID_c { get; set; }
public List<string> RE_ID_c { get; set; }
public C_SyntheseEvenement.Regroupement Regroupement_c { get; set; }
public C_SyntheseEvenement.Type Type_c { get; set; }
public DataSet DsDonnees_c = new DataSet();
public string Requete;
public ParamSyntheseEvtViewModel()
{
}
public ParamSyntheseEvtViewModel Initialiser()
{
Moteur_c = new Metaproductique.Kmprod.Km_Synthese_Moteur.C_SyntheseEvenement();
Moteur_c.Initialiser(C_Interface_Meta.Mesbdd_p, C_Interface_Meta.IndexBdd_p);
DtDebut_c = DateTime.Now.AddYears(-1);
DtFin_c = DateTime.Now;
return this;
}
public ParamSyntheseEvtViewModel Charger()
{
return this;
}
public class SearchSyntheseEvtViewModel
{
public C_DAL_TRS_ATELIER DAL_TRS_ATELIER_c;
public List<C_BEL_TRS_ATELIER> ListBEL_TRS_ATELIER_c;
public C_DAL_TRS_MACHINE DAL_TRS_MACHINE_c;
public List<C_BEL_TRS_MACHINE> ListBEL_TRS_MACHINE;
public ParamSyntheseEvtViewModel paramSynthese;
public SearchSyntheseEvtViewModel()
{
}
public SearchSyntheseEvtViewModel Initialiser()
{
this.DAL_TRS_ATELIER_c = new C_DAL_TRS_ATELIER(C_Interface_Meta.Mesbdd_p, C_Interface_Meta.IndexBdd_p);
this.DAL_TRS_MACHINE_c = new C_DAL_TRS_MACHINE(C_Interface_Meta.Mesbdd_p, C_Interface_Meta.IndexBdd_p);
paramSynthese = new ParamSyntheseEvtViewModel();
paramSynthese = paramSynthese.Initialiser();
paramSynthese = paramSynthese.Charger();
return this;
}
public SearchSyntheseEvtViewModel Charger()
{
DAL_TRS_ATELIER_c.Charger(ref ListBEL_TRS_ATELIER_c);
DAL_TRS_MACHINE_c.Charger(ref ListBEL_TRS_MACHINE);
return this;
}
}
public class ParamSyntheseEvtViewModel
{
public string AT_ID_c { get; set; }
public string TR_ID_c { get; set; }
public DateTime DtDebut_c;
public DateTime DtFin_c;
public Metaproductique.Kmprod.Km_Synthese_Moteur.C_SyntheseEvenement Moteur_c { get; set; }
public List<string> MA_ID_c { get; set; }
public List<string> RE_ID_c { get; set; }
public C_SyntheseEvenement.Regroupement Regroupement_c { get; set; }
public C_SyntheseEvenement.Type Type_c { get; set; }
public DataSet DsDonnees_c = new DataSet();
public string Requete;
public ParamSyntheseEvtViewModel()
{
}
public ParamSyntheseEvtViewModel Initialiser()
{
Moteur_c = new Metaproductique.Kmprod.Km_Synthese_Moteur.C_SyntheseEvenement();
Moteur_c.Initialiser(C_Interface_Meta.Mesbdd_p, C_Interface_Meta.IndexBdd_p);
DtDebut_c = DateTime.Now.AddYears(-1);
DtFin_c = DateTime.Now;
return this;
}
public ParamSyntheseEvtViewModel Charger()
{
return this;
}
在控制器中,我达到了我的方法
[HttpPost]
public ActionResult Search(SearchSyntheseEvtViewModel search)
{
ParamSyntheseEvtViewModel myParams;
myParams = search.paramSynthese;
if (myParams != null)
{
但是我的搜索ViewModel中的所有内容都为空...
我正在考虑与devextreme html元素有关。 我正在尝试将嵌套模型ParamSyntheseEvtViewModel绑定到控制器中的发布操作–
有人有什么主意吗?
答案 0 :(得分:0)
嘿,我解决了它:我缺少子模型的get / set属性!