As a promising technology to integrate renewable energy and enable decentralized energy management, microgrid (MG) offers an appealing network architecture due to its potential economic, environmental, and technical benefits. However, with the increasing deployment of intelligent devices and the growing network interconnectivity, communication channels and controllers for MGs become more vulnerable to emerging cyber threats. Two types of attacks are considered in this paper, including the data integrity attacks on the system status feedback and time-delay attacks which may disrupt the control of the MGs and lead to adverse consequences. A modified model predictive control (MPC) scheme is proposed for the secondary frequency control of MGs based on the online status switching method and generalized cross correlation (GCC) estimation to detect the real system status and time delay injected to the control system. The Euclidean metric is used in the online status switching method to obtain the real system states. Meanwhile, the GCC based delay estimation is developed to detect and track the time delay posed by attacks in the real-time operation. Case studies under different scenarios of the attacks are conducted, and the simulation results verify the effectiveness of the proposed MPC scheme under the cyberattacks.