Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

How do I run Controller methods from a View webpage?

$
0
0

Hi,

VS2013, MVC5, VB

I want to execute some server side code after the user clicks on a button and before the Form Submit takes place.  The following is what I have in place that is working (from a post on this forum):

...stuff<form id="simForm" method='post' target="_blank" action='https://test.authorize.net/gateway/transact.dll'>

  ...other stuff...
  <input type='button' onclick="UserCommit()" value="Submit Payment" class="btn btn-warning" /></form><script type="text/javascript">
  function UserCommit() {$("#simForm").submit()
  }</script>

This works with or without the type="text/javascript" attribute; I'm not certain I understand why.  At any rate, when the button is clicked the function 'UserCommit' is executed and the script executes the Submit.  So that's all pretty cool.  I then tried to insert the following 'get' call, but it doesn't seem to be working:

<script type="text/javascript">
  function UserCommit() {$.get("@Url.Action("ActionsBeforeSubmit", "Products")")$("#simForm").submit()
  }</script>

So I have a few questions about how this will work:

Q1) It would seem the controller action I'm calling can't be an ActionResult but needs to be a regular sub/function because doesn't an ActionResult drive another web page?

Q2) Am I supposed to be using a different syntax other than the <script> tags?

If anyone can help with the proper method to use to execute code back on the server before the script executes the Submit that would be great.

Thanks.

Best Regards,

Alan


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>