0

    貌似在一段紧张的忙碌之后,换来了短暂的休整,真的怀念去年那时候,做完了头儿分配的任务,就开始看自己喜欢的技术文章并做些练习,
每天都感到自己学到了很多东西.而如今开始负责一些项目了,大到理解需求
,设计edm,小到js,css什么都不能落下,同事以前都是做moss的,
很多事情得要我做个sample然后让他们模仿着做,为了进度
就算常常加班到10点或更晚,仍然总有做不完的事.

   而在启动这个项目之初,在讨论用什么框架,投了mvc.net一票,我是想着要跟着折腾一下。在得知这个项目是由我来负责,突然感到了
身上的压力
,功能模块不多,但是角色分的很多有10种,因此逻辑还是很复杂的,对于建模我倒不是很担心,之前的经历让我对建模十分有信心。
mvc.net1.0才发布1周左右,除了ms官方网站的那几篇文章,就很少看到资源了,因为之前的preview版本太多,而每个版本都有一些改进,
而我又不知道那些个版本和rtm究竟有多少区别.在一开始
我一边看需求文档,一边设计模型下班还要mvc练习当框架搭建好了,
开始添加功能了,没想到一开始就遇到一个错误,让我很无奈.在view表单验证失败时爆出一个异常,
 Validation of viewstate MAC failed error

    google了下发现在在mvc应用里面出现这种问题很少,在传统的web程序里面出现这种错误倒是不少,按照他们说的1,2,3..等解决办法一个个试过去,都没效果。
这让我很奇怪,在codeplex上找了些开源代码,看看似乎还是没有找到原因。晚上回家我不停的尝试用不同的的关键字在google.com上寻找,终于看到了一正解

http://www.dotneat.net/2008/12/13/ASPNETMVCValidationOfViewstateMACFailedError.aspx

If you get a Validation of viewstate MAC failed error on ASP.NET MVC, before trying to hard code your <machineKey attribute in web.config, 
disabling the keying of viewstate

<system.web>
  <pages enableViewStateMac="false" />
</system.web>

   , or any other literature you may want to check if the page you are posting data from has two "<form" attributes 
(the one hard coded on the page and the one created with Html.BeginForm) If you play with master templates and have
 to merge some MVC pages with tradicional ASP.NET you may get to that error.
显然webconfig里这段是没有用的<system.web>
  <pages enableViewStateMac="false" />
</system.web>

  any other literature you may want to check if the page you are posting data from has two "<form" attributes
(the one hard coded on the page and the one created with Html.BeginForm()). If you play with master templates and have to merge some MVC pages with tradicional ASP.NET you may get to that error.

这个才是主要的原因2个form标记嵌套的原因,如果在模板页中保留form标签,在view的内容页再使用Html.BeginForm())就相当于,2个form标签嵌套了,
当验证失败,由于不使用asp.net服务器端控件,没有viewstate,因此就有
Validation of viewstate MAC failed error 的错误,因此只需要将模板
也中的form标签去掉,就正常了。再回头看那些demo的代码的却是这样,哎都怪学习的时候,看东西不仔细。


http://www.cnblogs.com/subway-2008/archive/2009/07/21/1528155.html

关闭 返回顶部
联系我们
Copyright © 2011. 聚财吧. All rights reserved.