0

I have a cshtml file and a button that on click calls a javascript method.

@using (Html.BeginForm("PlayGameRound", "Games", new { id = Model.GameId, 
category = Model.Category }))
{
@Html.AntiForgeryToken()

<div class="form-group">
    <input type="submit" value="Play" style="float: left" id="play" onclick="@Model.Category = play()"/>
</div>

}

This is the javascript file method that is called.

function play() {
if (hideSpin) {
    return category;
  }
}

When i am running my program the javascript method is never called. How would I ensure the method is called when the button is clicked?

3
  • Its just onclick="play(). But you cannot assign it to a model property (razor is server side code) Commented Mar 26, 2018 at 6:08
  • I added just the play() now but how do I pass it to the controller method I have when submit is hit when I do not give the return value to something? Does it automatically go when I hit submit under the name category? Commented Mar 26, 2018 at 14:28
  • We have no idea what your trying to do here. What is hideSpin? What is category? What is it that you want to post back to the controller and bind to you model? Commented Mar 26, 2018 at 22:05

0

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.