为什么我不能将webform放入Views \Home文件夹? [英] Why can't I put the webform into Views\Home folder?

查看:70
本文介绍了为什么我不能将webform放入Views \Home文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Webform中使用ASP.NET MVC 5.2.2.0(C#)。

当我按照这一步执行时:

I'm using ASP.NET MVC 5.2.2.0 (C#) within Webform.
When I follow this step:

right click solution -> Add -> New item -> create new webform





调试后,当我输入localhost / webform1.aspx时,这没有问题在网址上。

但是,当我这样做时:



After debugging, that's work without a problem when I type "localhost/webform1.aspx" on url.
But, when I do this:

right click Views\Home folder -> Add -> Web form -> ok





HomeController.cs

public ActionResult Test()
{
return View("webform2");
}





RouteConfig.cs



In 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 }
            );
        }



当我在网址上输入localhost / home / test时,它给了我一个错误:


It gave to me an error when I type "localhost/home/test" on url:

The view at '~/Views/home/webform2.aspx must derive from ViewPage, ViewPage<TModel>...'



我的问题是:不能在Views \Home文件夹中创建webform吗?

如果可能的话,你能告诉我怎么做吗?



谢谢!


My question is: Can't webform be created in Views\Home folder?
If possible, can you tell me how to do that?

Thank you!

推荐答案

你不能混合和匹配MVC控制器和webforms。如果要使用webform将其放在views文件夹之外并直接访问它,而不是通过控制器。 Views文件夹是MVC查找MVC视图的地方。
You can't mix and match MVC controllers and webforms. If you want to use a webform place it outside of the views folder and access it direct, not via a controller. The Views folder is where MVC looks for MVC views.


这篇关于为什么我不能将webform放入Views \Home文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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