0

I have the following code

@using (Html.BeginForm("ConfirmBid", "Lot"))
{
    ...
    <input name="button" value="Place bid" type="submit" class="btn btn-size2" />
    ...
}

I want to run some JavaScript code when the button is pressed but only if the controller method ConfirmBid goes to a specific line of code (a success path). How might this be achieved?

1
  • 3
    your question is very unclear.can you make it some clear? Commented Nov 26, 2012 at 18:23

2 Answers 2

2

You can return JavaScriptResult from your action, that will execute js written in return value. See: http://mazharkaunain.blogspot.com/2011/02/how-to-use-aspnet-mvc-javascriptresult.html

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

Comments

1

Just output that javascript code you want to run conditionally. Perhaps something like this:

Output this for "failure" branch:

<input name="button" value="Place bid" type="submit" class="btn btn-size2" />

Output this for "success" branch":

<input name="button" value="Place bid" type="submit" class="btn btn-size2" onclick="return some_js_function()" />
<script type="text/javascript">
function some_js_function() {
    // your logic here
}

1 Comment

Problem is I want the button click to run some code as long as the action method takes a particular path - I don't see how this will help.

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.