哪里在ASP.Net MVC的表单字段从拿他们的价值观?他们的、字段、表单、价值观

2023-09-10 20:17:01 作者:酒、醉出人性

据我所知,如Html.TextBox字段()接受两个值,第一个是名称,第二个是该值。也是如此Html.TextArea()。但是在提交表单时为AJAX和那里的形式放在替换为来自服务器的视图股利的情况下,表单字段坚持服用previous值。图像胜过千言万语:

I understand that fields such as Html.TextBox() accept two values, the first one being the name and the second one being the value. And so does Html.TextArea(). But in a case where the form is submitted as AJAX and the div where the form is placed is replaced with a view from the server, the form fields insist on taking the previous values. An image is worth a thousand words:

我检查所有的控制器和模型上的图像是从调试视图本身。该模型是空的,但是从它产生的场拿previous提交的值。

I've checked everything on the controller and the model and the image is from debugging the view itself. The model is empty but the fields generated from it take the value of the previous submission.

推荐答案

回发数据在ModelState中举行。内置的HtmlHelper的方法呈现其内容时,会寻找存储在基于表单元素的名称,型号状态值。

The postback data is held in the ModelState. The built in HtmlHelper methods will look for values stored in the model state based on the name of the form element when rendering their content.