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

前端 未结 14 2238
挽巷
挽巷 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:51

    Be careful if your model type is String because the second parameter of View(string, string) is masterName, not model. You may need to call the overload with object(model) as the second paramater:

    Not correct :

    protected ActionResult ShowMessageResult(string msg)
    {
        return View("Message",msg);
    }
    

    Correct :

    protected ActionResult ShowMessageResult(string msg)
    {
        return View("Message",(object)msg);
    }
    

    OR (provided by bradlis7):

    protected ActionResult ShowMessageResult(string msg)
    {
        return View("Message",model:msg);
    }
    

提交回复
热议问题