# 错误：服务器操作失败。FormData 未定义或为空。

- **ID:** `nextjs/server-action-formdata-undefined`
- **领域:** nextjs
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

服务器操作的 FormData 未定义，因为表单提交时没有事件处理程序，或者表单元素上缺少 action 属性。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| next@14.2.0 | active | — | — |
| next@15.0.0 | active | — | — |
| react@18.3.0 | active | — | — |

## 解决方案

1. ```
   Ensure the form has an action prop pointing to the Server Action function, and the action is defined in a separate file or with 'use server' at the top of the action function.
   ```
2. ```
   Use the experimental useActionState hook with a client component to handle the form submission manually if the form must be a client component.
   ```

## 无效尝试

- **** — 'use server' should be on the Server Action function, not the component file. This causes the form to not recognize the action as a server action. (60% 失败率)
- **** — Server Actions require the form action attribute to properly bind FormData. onClick bypasses this and sends undefined. (80% 失败率)
- **** — Server Actions cannot be called directly from client components without 'use server' on the action function. This leads to undefined FormData. (70% 失败率)
