How do I add a confirmation popup on a button (GET POST action in MVC)?
I have a get/post/JSON function on an aspx page. This page adds data entered in a textbox to a table populated by javascript. When the user select the submit button. If the textbox is not empty, have a popup button telling the user the data in the textbox is not saved in the table. How do I have a confirm "ok/cancel" popup display on the post action in the Controller? I made a quick summary of what my code looks like.
...
<% using (Html.BeginForm("AddName", "Name", FormMethod.Post, new { id = "AddNameForm" })) { %>
...
<table id="displayNameTable" width= "100%">
<tr>
<th colspan="3">Names Already Added</th>
</tr>
<tr>
开发者_运维百科 <td style="font-size:smaller;" class="name"></td>
</tr>
</table>
...
<input name="Name" id="txtInjuryName" type="text" value="<%=test.Name %>" />
...
<input type="submit" name="add" value="Add"/>
<% } %>
<form id="form1" runat="server">
string confirmNext = "";
if (test.Name == "")
{
confirmNext = "return confirm('It seems you have a name not added.\n\nAre Continue?')";
}%>
<input type="submit" name="getNext" value="Next" onclick="<%=confirmNext%>" />
</form>
<script type="text/javascript">
$(document).ready(function(){ $("#form1").bind("submit", function(){
if(!confirm('It seems you have a name not added.\n\nAre Continue?'))
return false;
});}
});
</script>
You could use the form's onsubmit
event:
<form id="form1" onsubmit="return confirm('It seems you have a name not added.\n\nAre Continue?')">
<input type="submit" name="getNext" value="Next" />
</form>
Also why runat="server"
in an ASP.NET MVC application? Also you might consider specifying an action
that this form is posting to and use the Html.BeginForm
helper as for your first form.
精彩评论