错误如:未找到视图'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 }
);
}
}
发布于 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);
}
发布于 2013-08-16 20:34:09
问题:
在默认位置找不到您的View
。
说明:
视图应该位于与Controller
相同的文件夹或Shared
文件夹中。
解决方案:
将View
移动到MyAccount
文件夹或创建一个HomeController
。
Alternatives:
如果你不想移动你的View
或者创建一个新的Controller
,你可以在这个link上查看。
发布于 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:您的视图文件。
https://stackoverflow.com/questions/18273416
复制相似问题