Asp.net MVC, 谁吃了我的"id"参数值?

话说我有一个action:
public   void  SaveTask(Guid id,  string  title,  bool ?  isPublic )

准备让它接收"CreateTask"和"EditTask"创建的表单:
None.gif      < form  action ="SaveTask"  method ="post" >
None.gif        
< dl >
None.gif            
< dt > 标题 </ dt >
None.gif            
< dd >< input  type ="text"   value =""   size ="20"   name ="title"   id ="title"    /></ dd >
None.gif           
< dt > 公开 </ dt >
None.gifNone.gif         
< dd >< input  type ="checkbox"   value ="true"   name ="isPublic"    /> &nbsp; true </ dd >
None.gif        
</ dl >
None.gif      
< input  type ="hidden"   value ="00000000-0000-0000-0000-000000000000"   name ="id"   id ="id"    />
None.gif        
< input  type ="submit"   value ="创建任务"   name ="submit"   id ="submit"    />
None.gif    
</ form > None.gif
但是每次提交表单,都会出现异常:
None.gif [FormatException: GUID 应包含带  4  个短划线的  32  位数(xxxxxxxx - xxxx - xxxx - xxxx - xxxxxxxxxxxx)。]
None.gif   System.Guid..ctor(String g) 
+ 2284
None.gif   System.ComponentModel.GuidConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) 
+ 103
None.gif   System.ComponentModel.TypeConverter.ConvertFrom(Object value) 
+ 54
None.gif   System.Web.Mvc.Controller.ConvertParameterType(Object value, Type destinationType, String parameterName, String actionName) 
+ 161
None.gif
None.gif[InvalidOperationException: Cannot convert parameter 
'id' in action 'SaveTask' with value '' to type 'System.Guid' .]
None.gif   System.Web.Mvc.Controller.ConvertParameterType(Object value, Type destinationType, String parameterName, String actionName) 
+ 301
None.gif   System.Web.Mvc.Controller.InvokeActionMethod(MethodInfo methodInfo, RouteValueDictionary values) 
+ 760
None.gif
None.gif[InvalidOperationException: A value 
is  required  for  parameter  ' id '   in  action  ' SaveTask ' . The parameter either has no value or its value could not be converted. To make a parameter optional its type should either be a reference type or a Nullable type.]
None.gif   System.Web.Mvc.Controller.InvokeActionMethod(MethodInfo methodInfo, RouteValueDictionary values) 
+ 902
None.gif   System.Web.Mvc.Controller.InvokeAction(String actionName, RouteValueDictionary values) 
+ 263
None.gif   System.Web.Mvc.Controller.Execute(ControllerContext controllerContext) 
+ 161
None.gif   System.Web.Mvc.Controller.System.Web.Mvc.IController.Execute(ControllerContext controllerContext) 
+ 4
None.gif   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) 
+ 212
None.gif   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) 
+ 36
None.gif   System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) 
+ 4
None.gif   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
+ 358
None.gif   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean
&  completedSynchronously)  + 64
None.gif

注意加下划线的部分:不是明明有回传的值" 00000000-0000-0000-0000-000000000000"吗,怎么变成了空字符串了呢?谁吃了我的参数值?
  经过两个小时艰苦卓绝的调查取证(其中包含了到处搜索Asp.net MVC preview 2源码,以及试图使用Reflector重建源项目未遂),最后灵机一动,把"id"改成"taskId",于是就一切正常了.

  结论很显然,"id"这个参数名在默认情况下是受到特殊对待的,只能在URL里附带,不能post..
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值