首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >找不到视图或其母版,或者没有视图引擎支持搜索的位置

找不到视图或其母版,或者没有视图引擎支持搜索的位置
EN

Stack Overflow用户
提问于 2013-08-16 20:32:18
回答 15查看 193.7K关注 0票数 85

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

~/视图/我的帐户/LoginRegister.aspx

~/Views/MyAccount/LoginRegister.ascx

~/Views/Shared/LoginRegister.aspx

~/Views/Shared/LoginRegister.ascx

~/Views/MyAccount/LoginRegister.cshtml

~/Views/MyAccount/LoginRegister.vbhtml

~/Views/Shared/LoginRegister.cshtml

~/Views/Shared/LoginRegister.vbhtml

实际上,我的页面视图页面是~/Views/home/LoginRegister.cshtml,所以我要做的是

我的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 }
            );
        }
    }
EN

回答 15

Stack Overflow用户

发布于 2015-07-06 20:18:10

如果你的模型类型是string,要小心,因为(string,string)的第二个参数是masterName,而不是

不正确:

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

正确:

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

或(由bradlis7提供):

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

Stack Overflow用户

发布于 2013-08-16 20:34:09

问题:

在默认位置找不到您的View

说明:

视图应该位于与Controller相同的文件夹或Shared文件夹中。

解决方案:

View移动到MyAccount文件夹或创建一个HomeController

Alternatives:

如果你不想移动你的View或者创建一个新的Controller,你可以在这个link上查看。

票数 31
EN

Stack Overflow用户

发布于 2013-08-16 21:13:46

在Microsoft中,用于解析传入和传出ASP.net组合的路由引擎是按照约定优先于配置的思想设计的。这意味着,如果您遵循路由引擎使用的约定(规则),则不必更改配置。

ASP.net MVC的路由引擎不提供网页(.cshtml)。它为代码中的类提供了一种处理URL的方法,可以将文本/html呈现到输出流中,或者使用约定以一致的方式解析和提供.cshtml文件。

用于路由的约定是将控制器与名称类似于ControllerNameController的类匹配,即controller="MyAccount"表示查找名为MyAccountController的类。接下来是操作,该操作映射到控制器类中的函数,该函数通常返回一个ActionResult。也就是说,action="LoginRegister"将在控制器的类中查找函数public ActionResult LoginRegister(){}。此函数可能会返回一个View(),按照惯例,该the将被命名为LoginRegister.cshtml,并将存储在/Views/MyAccount/文件夹中。

总而言之,您将拥有以下代码:

/Controllers/MyAccountController.cs:

public class MyAccountController : Controller 
{
    public ActionResult LoginRegister()
    {
        return View();
    }
}

/Views/MyAccount/LoginRegister.cshtml:您的视图文件。

票数 14
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18273416

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档