ASP.NET MVC 2 - POST 后 ViewData 为空
我真的不知道在哪里寻找错误...情况:我有一个 ASPX 视图,其中包含一个表单和一些输入,当我单击“提交”按钮时,所有内容都会 POST 到我的一个 ASP。 NET MVC 操作。
当我在那里设置断点时,它被正确命中。当我使用 FireBug 查看发送到操作的内容时,我正确地看到 data1=abc&data2=something&data3=1234。
但是,我的操作方法中没有任何内容。 ViewData 为空,没有 ViewData["data1"] 或任何其他可以显示数据到达的内容。
怎么会这样呢?我可以从哪里开始寻找错误?
I don't really know where to look for an error... the situation: I have an ASPX view which contains a form and a few input's, and when I click the submit button everything is POST'ed to one of my ASP.NET MVC actions.
When I set a breakpoint there, it is hit correctly. When I use FireBug to see what is sent to the action, I correctly see data1=abc&data2=something&data3=1234.
However, nothing is arriving in my action method. ViewData is empty, there is no ViewData["data1"] or anything else that would show that data arrived.
How can this be? Where can I start looking for the error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当从控制器到视图时,ViewData 是相关的。它不会回发。
你需要你的操作方法看起来像这样
然后(模型?参数?)绑定应该为你处理事情
ViewData is relevant when going from the controller to the view. It won't post back.
you'll need your action method to look something like
Then the (model? parameter?) binding should take care of things for you
尝试修改您的操作以接受 FormCollection:
Try modifying your Action to accept FormCollection:
如果您想查看发布到视图的内容,请接受 FormCollection 作为参数,或将表单元素直接绑定到模型。像这样:
另外,请参阅此问题。
If you want to see what is posted to your View, accept FormCollection as a parameter, or bind your form elements directly to a model. Like so:
Also, see this question.
试试这个:
或者
或者
或者
try this:
or
or
or