Click here to Skip to main content
15,902,492 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
See more:
how to call javascript function from mvc controller
F-ES Sitecore 2-Jun-15 4:52am    
You can't call js from your controller. If you explain a bit more what it is you're trying to do someone might be able to help.
Mostafa Asaduzzaman 2-Jun-15 5:40am    
you can define the javascript function and through onclick event you can post to the controller action, thats way it will server the purpose that you want

1 solution

In the view you can define form elements such as input text, dropdown or text area and then define the button with an id and in the script call the click event and it will POST your form data to the controller

@using (Html.BeginForm("Submitform", "myControler", FormMethod.Post, new { @id = "form-submit", @class = "form-horizontal container"}))

---------code skipped 
--your form inputs
<div class="col-sm-8">
<input type="button" class="form-control">
<span class="btn btn-success " id="btn-submit">submit</span>

----code skipped

$('#btn-submit').on('click', function () 
   //check other condition here if you would like to

Hope this will help
Share this answer
Mostafa Asaduzzaman 2-Jun-15 22:16pm    
Have you tried with the trick yet?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900