为什么我不能将网络表单放入 Views/Home 文件夹?
Why can't I put the webform into Views/Home folder?
我在 Webform 中使用 ASP.NET MVC 5.2.2.0 (C#)。
当我执行此步骤时:right click solution -> Add -> New item... -> create new webform
调试后,当我在 url.
上键入 "localhost/webform1.aspx" 时没有问题
但是,当我这样做时:right click Views\Home folder -> Add -> Web form -> ok
在HomeController.cs
public ActionResult Test()
{
return View("webform2");
}
在RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{WebForm}.aspx/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
当我在 url:
上键入 "localhost/home/test" 时出现错误
The view at '~/Views/home/webform2.aspx must derive from ViewPage, ViewPage<TModel>...'
我的问题是:无法在Views\Home文件夹中创建webform?
如果可能的话,你能告诉我怎么做吗?
谢谢!
默认情况下 Views
文件夹有 web.config 文件阻止访问该文件夹中的所有项目。
修复:
- 更新 Views\web.config 以允许访问 Placing js files in the views folder
- 将网页表单放入他们自己的文件夹
我在 Webform 中使用 ASP.NET MVC 5.2.2.0 (C#)。
当我执行此步骤时:right click solution -> Add -> New item... -> create new webform
调试后,当我在 url.
上键入 "localhost/webform1.aspx" 时没有问题但是,当我这样做时:right click Views\Home folder -> Add -> Web form -> ok
在HomeController.cs
public ActionResult Test()
{
return View("webform2");
}
在RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{WebForm}.aspx/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
当我在 url:
上键入 "localhost/home/test" 时出现错误The view at '~/Views/home/webform2.aspx must derive from ViewPage, ViewPage<TModel>...'
我的问题是:无法在Views\Home文件夹中创建webform?
如果可能的话,你能告诉我怎么做吗?
谢谢!
默认情况下 Views
文件夹有 web.config 文件阻止访问该文件夹中的所有项目。
修复:
- 更新 Views\web.config 以允许访问 Placing js files in the views folder
- 将网页表单放入他们自己的文件夹