I want to call action from view using JavaScript, but I can't do this: Here is my code:
@if (ViewBag.Status == true)
{
<script language="javascript" type="text/javascript">
if (confirm("Some message"));
//And here i want to add action call
</script>
}
I'm trying to use @Html.Action, but this ruined script code and confirm message didn't show. When I write it as shown here: Calling ASP.NET MVC Action Methods from JavaScript:
@if (ViewBag.Status == true)
{
<script language="javascript" type="text/javascript">
if (confirm("Some message"));
{
$.ajax({
url: 'MyController/MyAction',
data: { id: id },
success: function () {
alert('Added');
}
});
}
</script>
}
nothing changed. It displays confirmation dialog but don't calling method