Reputation:
i have a button
and calling a function on its click
event. but respective controller-method is being executed twice on single click.
code
<input type="button" value="View Details" class="btn" id="happyNow" onclick="fun()"/>
<script>
function fun() {
alert('clicked!');
window.location = '../Surah_CRUD/Test';
}
</script>
controller method:
public class Surah_CRUDController : Controller
{
public ActionResult Test()
{
...
return View();
}
}
alert in script
hits only once but if i put some breakpoint
in controller, it is executed twice. how to fix it???
Upvotes: 0
Views: 316
Reputation:
it worked with following code:
<input type="button" value="View Details" id="meree" onclick=" return fun()" />
<script>
function fun() {
var request = $.ajax({
url: '../Surah_CRUD/fuck',//action method url which defined in controller
type: 'get',
cache: false,
data:'',
dataType: 'json',
contentType: 'application/json; charset=utf-8'
});
return false;
}
</script>
Upvotes: 0
Reputation: 34895
The button submits the form it is in. You don't have a separate controller action that receives the submitted model so the same action is being hit. The method on click also requests the controller action.
Upvotes: 2