Several methods for implementing button submission in ASP. NET MVC

Source: Internet
Author: User

Sometimes this problem occurs: Multiple buttons are required on a form to complete different functions, such as a simple approval function.

If webform is used, it does not need to be discussed. However, a form in asp.net mvc can only be submitted to one Action for processing, which is relatively troublesome.

 

Use client scripts

<input type="submit" value="Approved" onclick='this.form.action="<%=Url.Action("Action1") %>";' />

<input type="submit" value="Review failed" onclick='this.form.action="<%=Url.Action("Action2") %>";'  />

<input type="submit" value="Back" onclick='this.form.action="<%=Url.Action("Action3") %>";' />

 

OrDirectly include querystring

<Input type = "submit" value = "approved" onclick = 'this. form. action = "<% = Url. Action (" Action1 ") %>? Act = 1 "; '/>

<Input type = "submit" value = "REJECTED" onclick = 'this. form. action = "<% = Url. Action (" Action2 ") %>? Act = 2 "; '/>

<Input type = "submit" value = "return" onclick = 'this. form. action = "<% = Url. Action (" Action3 ") %>? Act = 3 "; '/>

 

When you click the submit button, first change the Form action attribute so that the Form is submitted to the corresponding action of the button for processing.

Sometimes this problem occurs: Multiple buttons are required on a form to complete different functions, such as a simple approval function.

If webform is used, it does not need to be discussed. However, a form in asp.net mvc can only be submitted to one Action for processing, which is relatively troublesome.

 

Use client scripts

<input type="submit" value="Approved" onclick='this.form.action="<%=Url.Action("Action1") %>";' />

<input type="submit" value="Review failed" onclick='this.form.action="<%=Url.Action("Action2") %>";'  />

<input type="submit" value="Back" onclick='this.form.action="<%=Url.Action("Action3") %>";' />

 

OrDirectly include querystring

<Input type = "submit" value = "approved" onclick = 'this. form. action = "<% = Url. Action (" Action1 ") %>? Act = 1 "; '/>

<Input type = "submit" value = "REJECTED" onclick = 'this. form. action = "<% = Url. Action (" Action2 ") %>? Act = 2 "; '/>

<Input type = "submit" value = "return" onclick = 'this. form. action = "<% = Url. Action (" Action3 ") %>? Act = 3 "; '/>

 

When you click the submit button, first change the Form action attribute so that the Form is submitted to the corresponding action of the button for processing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.