2

I have googled a lot about this question but couldn't find any help regarding my scenario. So, here is the question
I have a form containing a single drop down, named Sections, user can select a Section and then user have two choices.
1-Add File to this Section By Going To File Uploading Form
2-Add Further Subsection By Going to Add Section Form
This is image of my form

enter image description here

 @using (Html.BeginForm("SectionForm","Sections"))
    {
    <div class="form-group">
        @Html.DisplayFor(s => s.SectionName)
        @Html.DropDownListFor(s => s.SelectedSection, new SelectList(Model.Sections,"SectionId","SectionName"),"Select a Section",new {@class = "form-control",autofocus="autofocus"} )
    </div>
    <p>
        If you don't see your desired section here, Click <strong>Add Section</strong>.
    </p>
    <button type="submit" class="btn btn-primary">Add Further Subsection</button>

      <br />
     <a href="@Url.Action("FileForm","LawFiles",new { sectionId =  Model.SelectedSection })" class="btn btn-primary">Add File</a>
}
<br>

SectionForm and FileForm are my actions and Sections and LawFiles are controllers.
anchor tag at the end won't work until I don't submit the form

Yogi
  • 9,174
  • 2
  • 46
  • 61
awebartisan
  • 1,424
  • 16
  • 27

1 Answers1

1

You could use javascript to modify the action of your form. You’ll add a click event on the submit button and overwrite the default submit action.

 <html>
 <body>
    <form id="myform">
           <input type="submit" id="submit1"/>
           <input type="submit" id="submit2"/>
    </form>
 </body>
 <script>
    $("#submit1").click(function() {
    document.myform.action = “http://localhost/controller/action1”;
    });
    $("#submit2").click(function() {
      document.myform.action = “http://localhost/controller/action2”; 
    });
 </script>
</html>
Sain Pradeep
  • 3,119
  • 1
  • 22
  • 31