【问题标题】:Submit button is not working in asp.net mvc提交按钮在 asp.net mvc 中不起作用
【发布时间】:2013-05-02 21:00:36
【问题描述】:

我有一个模型:

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几天,请帮忙

【问题讨论】:

标签: c# asp.net-mvc asp.net-mvc-4 razor


【解决方案1】:

改变

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

到

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    • 2013-04-09
    • 1970-01-01
    相关资源
    最近更新 更多