5

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

1

1 Answer 1

15

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.