In other words, I have an action: Public void SaveTask (Guid id, string title, bool? IsPublic)
Prepare it to receive the forms created by "CreateTask" and "EditTask: <Form action = "SaveTask" method = "post">
<Dl>
<Dt> title </dt>
<Dd> <input type = "text" value = "" size = "20" name = "title" id = "title"/> </dd>
<Dt> Publish </dt>
<Dd> <input type = "checkbox" value = "true" name = "isPublic"/> & nbsp; true </dd>
</Dl>
<Input type = "hidden" value = "00000000-0000-0000-0000-000000000000" name = "id" id = "id"/>
<Input type = "submit" value = "Create task" name = "submit" id = "submit"/>
</Form>
However, every time a form is submitted, an exception occurs: [FormatException: The GUID should contain 32 digits with four dashes (xxxxxxxx-xxxx-xxxxxxxxxxxx).]
System. Guid .. ctor (String g) + 2284
System. ComponentModel. GuidConverter. ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, Object value) + 103
System. ComponentModel. TypeConverter. ConvertFrom (Object value) + 54
System. Web. Mvc. Controller. ConvertParameterType (Object value, Type destinationType, String parameterName, String actionName) + 161
[InvalidOperationException:Cannot convert parameter'Id' in action 'savetask 'with value' to type 'System. guid'.]
System. Web. Mvc. Controller. ConvertParameterType (Object value, Type destinationType, String parameterName, String actionName) + 301
System. Web. Mvc. Controller. InvokeActionMethod (MethodInfo methodInfo, RouteValueDictionary values) + 760
[InvalidOperationException: A value is required for parameter 'id' in action 'savetask '. the parameter either has no value or its value cocould not be converted. to make a parameter optional its type shoshould either be a reference type or a Nullable type.]
System. Web. Mvc. Controller. InvokeActionMethod (MethodInfo methodInfo, RouteValueDictionary values) + 902
System. Web. Mvc. Controller. InvokeAction (String actionName, RouteValueDictionary values) + 263
System. Web. Mvc. Controller. Execute (ControllerContext controllerContext) + 161
System. Web. Mvc. Controller. System. Web. Mvc. IController. Execute (ControllerContext controllerContext) + 4
System. Web. Mvc. MvcHandler. ProcessRequest (HttpContextBase httpContext) + 212
System. Web. Mvc. MvcHandler. ProcessRequest (HttpContext httpContext) + 36
System. Web. Mvc. MvcHandler. System. Web. IHttpHandler. ProcessRequest (HttpContext httpContext) + 4
System. Web. CallHandlerExecutionStep. System. Web. HttpApplication. IExecutionStep. Execute () + 358
System. Web. HttpApplication. ExecuteStep (IExecutionStep step, Boolean & completedSynchronously) + 64
Note the underlined part: Isn't there a clear return value "00000000-0000-0000-0000-000000000000"? How does it become a null string? Who has taken my parameter value?
After two hours of arduous investigation and evidence collection (including searching for the source code of Asp.net MVC preview 2 and attempting to use Reflector to re-build the source project,Change "id" to "taskId"So everything is normal.
Obviously, the parameter name "id" is specially treated by default and can only be included in the URL, not post ..