[英]Submit button is not working in asp.net mvc
我有一个模型:
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的几天请帮忙
更改
<input id="btnSubmit" type="button" value="Submit" />
至
<input id="btnSubmit" type="submit" value="Submit" />
您应该使用submit
而不是button
来输入元素type
属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.