Reputation: 1187
In my ASP.NET MVC view,
@using (Html.BeginForm("MyAction","MyController",FormMethod.Post))
{
<input type="submit" id="submitSelectedItems" value="Add to Items" />
}
Also I have a Jquery onclick event for the submit button,
$a("#submitSelectedItems").on("click", function () {
if (SelectedItem.length <= 0) {
alert("Please select a style to proceed!!");
return flase;
}
else {
return true;
}
return flase;
});
Here I am successfully getting the alert when ever there is no items selected, however after the alert eventhough I am returning false, here the post to the action method is not stopped, it continuous with that? How can I stop posting? I even tried with e.preventDefault();
, but no luck.
Upvotes: 0
Views: 1530
Reputation: 870
You are returning flase;
Please check your code once again. It should return false
,
$a("#submitSelectedItems").on("click", function () {
if (SelectedItem.length <= 0) {
alert("Please select a style to proceed!!");
return false; //you have spelled wrong false as flase
}
else {
return true;
}
return false; //you have spelled wrong false as flase
});
Upvotes: 1