1
我有2个文本框和一个按钮。刷新页面时会自动插入数据?
目标是保存按钮单击文本框数据并清空文本框,以便为下一个条目做好准备。
即使按钮单击后文本框看起来为空,问题仍然存在。如果我刷新页面,最后插入的值会自动插入到数据库中。
页面代码:
<script type="text/javascript">
$(document).ready(function() {
$("#Time").val("");
$("#Title").val("");
});
</script>
<%Html.EnableClientValidation(); %>
<% using (Html.BeginForm())
{ %>
<div id="fullform">
<h2>Enter the program list</h2>
<div id="CreateData">
<div>
<%:Html.LabelFor(m=>m.Year) %>
</div>
<div>
<%:Html.TextBoxFor(m=>m.Year) %>
</div>
<div>
<table>
<tr>
<td><%:Html.LabelFor(m=>m.Time) %></td>
<td><%:Html.LabelFor(m=>m.Title) %></td>
<td></td>
</tr>
<tr>
<td><%:Html.TextBoxFor(m => m.Time)%></td>
<td><%:Html.TextBoxFor(m=>m.Title) %></td>
<td><input type="image" value="Register" src="../../Content/images/btnAdd.png"/></td>
</tr>
</table>
</div>
我在做什么错?
没有因为插入的数据会在底部 – kandroid
显示我不能重定向到一个不同的页面,我认为你仍然可以使用Post/Redirect/Get模式,请参阅此博客文章以获取一个asp.net MVC特定示例 - http://www.stevefenton.co.uk/Content/Blog/Date/201104/Blog/ASP-NET-MVC-Post -Redirect-Get-Pattern/ – ipr101
干杯兄弟。这解决了我的问题。 – kandroid