I have a Model:
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; }
}
and i've created a strongly typed view for this model:
@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" />
}
My controller:
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);
}
when I submitting the button newform remains empty.. I debug it and found the submit button is not triggering or sending values to newform. I am just a few days in MVC please help
Change
<input id="btnSubmit" type="button" value="Submit" />
To
<input id="btnSubmit" type="submit" value="Submit" />
You should use submit
instead of button
for input element type
attribute
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With