ASP.NET MVC 2 - ViewData的POST后空 [英] ASP.NET MVC 2 - ViewData empty after POST

查看:267
本文介绍了ASP.NET MVC 2 - ViewData的POST后空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不知道去哪里找一个错误...的情况:我有一个包含一个表单和几个输入的一个ASPX视图,当我点击提交按钮一切POST'ed到之一我的ASP.NET MVC行动。

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.

当我设置一个断点,它被正确击中。当我使用萤火看到什么是发送到行动,我看到正确的数据1 = ABC&放大器;数据2 =东西和放大器;数据3 = 1234。

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.

但是,没有抵达我的操作方法。 ViewData的是空的,没有计算机[数据1]或其他任何东西,将显示该数据到达。

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?

推荐答案

从控制器到视图中去时,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

public ActionResult DoSomething(string data1, string data2, int data3) { ...

那么(型号?参数?)的结合应该照顾你的东西。

Then the (model? parameter?) binding should take care of things for you

这篇关于ASP.NET MVC 2 - ViewData的POST后空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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