The view or its master was not found or no view engine supports the searched locations

前端 未结 14 2279
挽巷
挽巷 2020-12-02 15:05

Error like:The view \'LoginRegister\' or its master was not found or no view engine supports the searched locations. The following locations were searched:

14条回答
  •  旧巷少年郎
    2020-12-02 15:41

    If the problem happens intermittently in production, it could be due to an action method getting interrupted. For example, during a POST operation involving a large file upload, the user closes the browser window before the upload completes. In this case, the action method may throw a null reference exception resulting from a null model or view object. A solution would be to wrap the method body in a try/catch and return null. Like this:

    [HttpPost]
    public ActionResult Post(...)
    {
        try
        {
            ...
        }
        catch (NullReferenceException ex)  // could happen if POST is interrupted
        {
            // perhaps log a warning here
            return null;
        }
    
        return View(model);
    }
    

提交回复
热议问题