未找到视图或其母版或没有视图引擎支持搜索的位置 [英] The view or its master was not found or no view engine supports the searched locations

查看:30
本文介绍了未找到视图或其母版或没有视图引擎支持搜索的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误如:未找到视图LoginRegister"或其主视图,或者没有视图引擎支持搜索的位置.搜索了以下位置:

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

~/Views/MyAccount/LoginRegister.aspx

~/Views/MyAccount/LoginRegister.aspx

~/Views/MyAccount/LoginRegister.ascx

~/Views/MyAccount/LoginRegister.ascx

~/Views/Shared/LoginRegister.aspx

~/Views/Shared/LoginRegister.aspx

~/Views/Shared/LoginRegister.ascx

~/Views/Shared/LoginRegister.ascx

~/Views/MyAccount/LoginRegister.cshtml

~/Views/MyAccount/LoginRegister.cshtml

~/Views/MyAccount/LoginRegister.vbhtml

~/Views/MyAccount/LoginRegister.vbhtml

~/Views/Shared/LoginRegister.cshtml

~/Views/Shared/LoginRegister.cshtml

~/Views/Shared/LoginRegister.vbhtml

~/Views/Shared/LoginRegister.vbhtml

实际上我的页面查看页面是 ~/Views/home/LoginRegister.cshtml 所以我做什么

Actually my page view page is ~/Views/home/LoginRegister.cshtml so what i do

而我的 RouteConfig

 public class RouteConfig
    {

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "MyAccount", action = "LoginRegister", id = UrlParameter.Optional }
            );
        }
    }

推荐答案

注意如果你的模型类型是String,因为View(string, string)的第二个参数是masterName,不是模型.您可能需要使用 object(model) 作为第二个参数调用重载:

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:

不正确:

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

正确:

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

OR(由 bradlis7 提供):

OR (provided by bradlis7):

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

这篇关于未找到视图或其母版或没有视图引擎支持搜索的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆