Asp.NET MVC Html.TextBox刷新问题 [英] Asp.NET MVC Html.TextBox refresh problem

查看:358
本文介绍了Asp.NET MVC Html.TextBox刷新问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有asp.net的MVC 2和html.textboxfor助手的一个问题。
我用的是后续code的形式:

i have a problem with asp.net mvc 2 and the html.textboxfor helper. i use the follow code in a form:

<%= Html.TextBoxFor(model => model.Zip, new { @class = "txt", id = "zip", tabindex = 1 })%>

当用户发送的形式,我验证了拉链code,当拉链是无效的,我们设定的修正拉链。
我的模型修正拉链,从ASP生成的HTML code包含旧拉链值。

when the user send the form, i validate the zipcode, when the zip is invalid we set the corrected zip. my model has the corrected zip, the generated html code from asp contains the old zip value.

示例:
用户写邮编:12345
我的验证类,修正德zip包:12346
我的模型包含新邮编:123456,在GUI上我看到的只有12345

sample: user write zip: 12345 my validation class, corrected teh zip to: 12346 my model contains the new zip: 123456, on the gui i see only 12345

这是什么问题?

推荐答案

您不能修改在你的控制器动作值,因为生成的文本框时,助手将始终使用张贴的值。这是由设计,如果你想要解决它,你将不得不写了自己的助手或手动生成文本框​​:

You cannot modify the values in your controller action because the helper will always use the POSTed values when generating the textbox. This is by design and if you want to workaround it you will have to write your own helper or generate the textbox manually:

<input 
    type="text" 
    name="Zip" 
    value="<%= Html.Encode(Model.Zip) %>" 
    class="txt" 
    id="zip" 
    tabindex="1" 
/>

这篇关于Asp.NET MVC Html.TextBox刷新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆