5

我有一个模型:

public class FormCreateModel
{
    public FormModel formInfo { get; set; }
    public FieldModel fieldInfo { get; set; }
    public InstitutionModel selectedInst { get; set; }
    public FormTypeModel selectedFormType { get; set; }
    public CategoryModel categoryInfo { get; set; }
    public List<InstitutionModel> institutions { get; set; }
    public List<FormTypeModel> FormTypes { get; set; }
}

我为这个模型创建了一个强类型视图:

@using (Html.BeginForm()) 
{ 
    <p>
        @Html.LabelFor(lbl =>lbl.selectedInst.Institution_Name, "Institution Name :", new { @class="lblName"})
        @Html.DropDownListFor(drpdown => drpdown.selectedInst.Institution_Name, new SelectList(Model.institutions.Select(inst => inst.Institution_Name)),"-- select Institution--", new { @class ="txtFormtext"})
    </p>

    <p>
        @Html.LabelFor(lbl => lbl.formInfo.form_Name, "Form Name", new {@class ="lblName"})
        @Html.TextBoxFor(txtbox => txtbox.formInfo.form_Name, new { @class ="txtFormtext"})
    </p>

    <p>
        @Html.LabelFor(lbl => lbl.formInfo.form_Desc, "Form Description", new {@class ="lblName" })
        @Html.TextAreaFor(txtbox => txtbox.formInfo.form_Desc,4,5,new { @class ="txtFormtext"})
    </p>

    <p>
        @Html.LabelFor(lbl => lbl.formInfo.ActivationDate, "Form Activation Date", new {@class ="lblName :" })
        @Html.DropDownListFor(drpdown => drpdown.formInfo.ActivationDate.day, new SelectList(Enumerable.Range(1,31)),"Day", new {@class="slctDate"})            
        @Html.DropDownListFor(drpdown => drpdown.formInfo.ActivationDate.month, new SelectList(Enumerable.Range(1,12)),"Month", new {@class="slctDate"})
        @Html.DropDownListFor(drpdown => drpdown.formInfo.ActivationDate.year, new SelectList(Enumerable.Range(DateTime.Now.Year, DateTime.Now.Year + 4)),"Year", new {@class="slctDate"})                 
     </p>

     <p>
        @Html.LabelFor(lbl => lbl.formInfo.ExpireDate, "Form Expiration Date", new {@class ="lblName" })
        @Html.DropDownListFor(drpdown => drpdown.formInfo.ExpireDate.day, new SelectList(Enumerable.Range(1,31)),"Day", new {@class="slctDate"})            
        @Html.DropDownListFor(drpdown => drpdown.formInfo.ExpireDate.month, new SelectList(Enumerable.Range(1,12)),"Month", new {@class="slctDate"})
        @Html.DropDownListFor(drpdown => drpdown.formInfo.ExpireDate.year, new SelectList(Enumerable.Range(DateTime.Now.Year, DateTime.Now.Year + 4)),"Year", new {@class="slctDate"})
     </p>

     <p>
        @Html.LabelFor(lbl => lbl.formInfo.Logo, "Form Description", new {@class ="lblName" })
        @Html.TextBoxFor(txtbox => txtbox.formInfo.Logo,new { @class ="txtFormtext"})
     </p>
    <p>
        @Html.LabelFor(lbl => lbl.selectedFormType.FormTypeName, "Form Type", new {@class ="lblName" })
        @Html.DropDownListFor(drpdown => drpdown.selectedFormType.FormTypeName, new SelectList(Model.FormTypes.Select(m => m.FormTypeName)), "--- select form type---", new {@class="txtFormtext" })
     </p>

     <input id="btnSubmit" type="button" value="Submit" />  
}     

我的控制器:

public ActionResult createNewForm(FormCreateModel newForm)
{
    InstitutionManagement im = new InstitutionManagement();
    newForm.institutions = im.getInstitution();
    FormManagement fm = new FormManagement();
    newForm.FormTypes = fm.getFormType();
    return View("createNewForm", newForm);
}

当我提交按钮时,newform 仍然为空。我对其进行了调试,发现提交按钮没有触发或向 newform 发送值。我在 MVC 中只有几天,请帮忙

4

1 回答 1

15

改变

<input id="btnSubmit" type="button" value="Submit" />

<input id="btnSubmit" type="submit" value="Submit" />

您应该使用submit而不是button输入元素type属性

于 2013-05-08T15:01:06.830 回答