Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
See more:
how to call javascript function from asp.net mvc controller
Posted
Comments
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

HTML
@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>
</div>

----code skipped
}


<script>
$('#btn-submit').on('click', function () 
{
   //check other condition here if you would like to
        $('form#form-submit').submit();
    });</script>


Hope this will help
 
Share this answer
 
v3
Comments
Mostafa Asaduzzaman 2-Jun-15 22:16pm    
@Rocky
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