mar*_*tin 9 asp.net asp.net-mvc caching refresh html.textbox
我有一个asp.net mvc 2和html.textboxfor助手的问题.我在表单中使用以下代码:
<%= Html.TextBoxFor(model => model.Zip, new { @class = "txt", id = "zip", tabindex = 1 })%>
Run Code Online (Sandbox Code Playgroud)
当用户发送表单时,我验证了zipcode,当zip无效时我们设置了更正后的zip.我的模型有更正的zip,从asp生成的html代码包含旧的zip值.
示例:用户写拉链:12345我的验证类,更正了拉链:12346我的模型包含新拉链:123456,关于gui我只看到12345
问题是什么?
您无法修改控制器操作中的值,因为生成文本框时帮助程序将始终使用POSTed值.这是设计使然,如果您想解决它,您将必须编写自己的帮助程序或手动生成文本框:
<input
type="text"
name="Zip"
value="<%= Html.Encode(Model.Zip) %>"
class="txt"
id="zip"
tabindex="1"
/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4834 次 |
| 最近记录: |