Asp.net MVC, who has taken my "id" parameter value?

Source: Internet
Author: User
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 ..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.