Usman Azam
Usman Azam

Reputation: 39

Can an HTML button call an MVC Controller Action method

Can I write this code for calling an MVC Controller and Action method?

<input type="button" value="Next" onclick="location.href='<%: Url.Action("Create", "StudentInfo") %> '"/>

Upvotes: 1

Views: 222

Answers (1)

Derrick
Derrick

Reputation: 2552

While using the onclick handler may work, it relies unnecessarily on JavaScript. You may find using a form submission to be cleaner:

<form action="<%: Url.Action("Create", "StudentInfo") %>" method="get">
    <input type="submit" value="Next" />
</form>

Upvotes: 1

Related Questions