In this work, a 3D undulatory locomotion model inspired by Caenorhabditis elegans is constructed. Following the anatomical structure of C. elegans, the body of the model is represented as a multi-joint rigid link system with 12 links. The angle between two consecutive links is determined by the muscle lengths in four quadrants that are controlled by the nervous system. The nervous system of this locomotion model is represented by a dynamic neural network (DNN) that involves three parts: head DNN, central pattern generator (CPG), and body DNN. The head DNN decides turning or not, and CPG produces the sinusoid waves that are transmitted through the body DNN to control the lengths of muscles. The 3D locomotion behavior is achieved by using the DNN to control the muscle lengths, and then using the muscle lengths to control the angles between two consecutive links on both horizontal plane and vertical plane. In this work, the relations between the outputs of DNN and muscle lengths, as well as the muscle lengths and the angles between two consecutive links, are determined. Furthermore, due to the learning capability of DNN, a set of nonlinear functions that are designed to represent the chemotaxis behaviors of C. elegans are learned by the head DNN using Differential Evolution Algorithm. The testing results show good 3D performance of this locomotion model in both forward and backward locomotion, as well as slight turn and Ω turn. Furthermore, this locomotion model performs the chemotaxis behaviors of finding food and avoiding toxin successfully. Finally, quantitative analyses by comparing with the experiment results are provided to verify the realness and effectiveness of this locomotion model, which could serve as a prototype for the worm-like robot.