I want to migrate existing asp.net application to asp.net MVC pattern format now. What procedure should I will follow? Any step-by-step instructions would be very helpful.
我现在想将现有的asp.net应用程序迁移到asp.net MVC模式格式。我应该遵循什么程序?任何一步一步的指导都非常有用。
4 个解决方案
#1
67
These is my step-by-step guide, based on steps we have taken at my company during our move from a classic ASP.Net Webforms to ASP.Net MVC. It's not perfect, and still ongoing since we have to do this in stages because of the size of the site, but perhaps someone else will find and file an improved answer based on our results.
这是我的一步一步指导,基于我们在公司从一个典型的ASP中所采取的步骤。净Webforms ASP。净MVC。它并不完美,而且还在进行中,因为由于站点的大小,我们必须分阶段进行,但是也许其他人会根据我们的结果找到并提交一个改进的答案。
Stages: 1. Planning - moving to MVC from Web Forms in ASP.Net requires some careful planning. The mistake we made in our move is not realising that there are are really two aspects to this stage of planning, route planning and model/controller/action planning. Not doing this will cause serious issues later on as you try to extend functionality of your site or hit more complex migrations.
阶段:1。规划——从ASP中的Web表单迁移到MVC。Net需要一些仔细的计划。我们在行动中犯的错误是没有意识到,在计划、路线规划和模型/控制器/行动计划这一阶段实际上有两个方面。当您尝试扩展站点的功能或进行更复杂的迁移时,不这样做将导致严重的问题。
Tips: - Look at your current sitemap, and design the improved sitemap/directory structure to be used in the ASP.Net MVC application. Figure out a 'language' for your website, e.g. the default behaviour of ASP.Net MVC is to have a http://sitename/{controller}/{action}/{id} behavior, but you can override this as you gain more experience hacking routing rules.
提示:-查看您当前的站点地图,并设计改进的站点地图/目录结构将在ASP中使用。净MVC应用程序。为你的网站找出一种“语言”,例如ASP的默认行为。Net MVC将具有http://sitename/{controller}/{action}/{id}行为,但随着您获得更多破解路由规则的经验,您可以重写此行为。
-
Remember by default each Controller will be routed to via a virtual subdirectory of your application, e.g. http://sitename/X would route to XController (and by default its Index method), http://sitename/Y/Get would route to YController's Get() method. You can change this as you please (routing's really powerful), but that's beyond the scope of this answer.
记住,默认情况下,每个控制器都将通过应用程序的一个虚拟子目录被路由到,例如http://sitename/X将路由到XController(默认情况下是它的索引方法),http://sitename/Y/Get将路由到YController的Get()方法。您可以随意更改它(路由非常强大),但这超出了这个答案的范围。
-
Using the existing sitemap, specify what folder in the MVC structure each current .aspx page should fall (of course, first ask if it should exist at all).
使用现有的sitemap,指定MVC结构中每个当前的.aspx页面应该放置的文件夹(当然,首先要问它是否应该存在)。
-
If Scripts, Images etc are not stored together, or in some 'reserved name' folders within each subdirectory, consider doing so now as you're redesigning. This is as it would greatly simplify your design by allowing you to use a Map.IgnoreRoute() routing rule command in the Global.aspx.cs file to bypass processing these folders as routes.
如果脚本、图像等没有存储在一起,或者在每个子目录中的某个“保留名称”文件夹中,请在重新设计时考虑这样做。通过允许您在Global.aspx中使用Map.IgnoreRoute()路由规则命令,可以大大简化设计。cs文件绕过处理这些文件夹作为路由。
In our case we mirrored the real subdirectory layout of the current site, where each subdirectory became a controller, e.g. /Account would have an AccountController, /X would have XController. All pages that fell inside there were replaced by actions within each Controller. e.g. http://sitename/profile/about.aspx now became http://sitename/profile/about and mapped to the "about" ActionResult method inside the profileController. This is allowing us to stay agile by doing a partial migration of one or two directories (or several files inside one directory) over a series of sprints, rather than having to migrate the entire site in one go over a much longer duration.
在我们的例子中,我们反映了当前站点的实际子目录布局,其中每个子目录成为一个控制器,例如,/Account将有一个AccountController, /X将有XController。所有位于其中的页面都被每个控制器中的操作所取代。例如,http://sitename/profile/about。aspx现在变成了http://sitename/profile/about并映射到profileController的“about”ActionResult方法。这允许我们通过在一系列的sprint中进行一两个目录(或者一个目录中的几个文件)的部分迁移,而不是在一段时间内迁移整个站点,从而保持敏捷。
-
Create a new ASP.Net MVC application in Visual Studio and immediately create the rules in the Global.asax file that ignore routing rules for the folders that exist in the current site.
创建一个新的ASP。Net MVC应用程序在Visual Studio中,并立即在全局中创建规则。忽略当前站点中存在的文件夹的路由规则的asax文件。
-
Copy the folders from the ASP.Net Web Application to the ASP.Net MVC Application folders. Run the website and ensure it works properly (it should as no routing rules are being used yet).
从ASP拷贝文件夹。Net Web应用程序到ASP。净MVC应用程序文件夹。运行网站并确保它正常工作(它应该还没有使用路由规则)。
-
Pick a subdirectory or subset of files within a subdirectory to migrate.
选择一个子目录或子目录中的文件子集来迁移。
-
For each .aspx page inside this subdirectory:
对于本子目录中的每个.aspx页面:
a. Create its View first. I tend to use the web-browser rendered version of the page as my base HTML, and then put placeholders in the locations that I know are filled with dynamic data.
首先创建视图。我倾向于使用web浏览器渲染的页面版本作为我的基本HTML,然后在我知道充满动态数据的位置放置占位符。
b. Using the placeholders for the dynamic data, create a first-draft of the Model using simple data types. This model will start off simple, but be constantly refactored as you migrate more pages from the original site, so don't worry if it starts looking a little heavy. If you find yourself with too many Properties in one Model for your taste, or see a logical grouping beyond just the Model of certain subset of items, perhaps this is a sign the Model needs to be refactored to have an object instead with these simple data types as properties but is composed in the business logic layer.
b.使用动态数据的占位符,使用简单的数据类型创建模型的初稿。这个模型一开始很简单,但是当您从原始站点迁移更多的页面时,会不断地重构它,所以如果它看起来有点重,不要担心。如果你发现自己有太多的属性在一个模型你的口味,或看到一个不仅仅是逻辑分组模型项目的某些子集,也许这是一个信号模型需要重构对象而不是与这些简单的数据类型属性,但在业务逻辑层组成。
c. Create the controller if it hasnt been created yet, and put the appropriate ActionResult method for the Action your planning has determined should route to this view. If you realise something that there is a new action that doesn't map to a page from the old site, then create the View for the controller, and include appropriate //TODO: tags so you can keep track of this to implement after you have migrated the existing pages.
c.如果还没有创建控制器,就创建它,并为您的计划确定的应该路由到该视图的操作放置适当的ActionResult方法。如果您意识到有一个新动作没有映射到来自旧站点的页面,那么为控制器创建视图,并包含适当的//TODO:标记,以便在迁移现有页面之后跟踪该动作以实现。
d. Consider putting in some handling code for unknown actions as well, if you don't have a {*catchall} Routing rule for this already in your global.asax.cs file.
d.如果您没有在您的global.asax中已经有这样的{* *catch - all}路由规则,那么考虑为未知操作输入一些处理代码。cs文件。
e. Create the constructor classes for the Model so that given certain parameters that the Controller will have (passed in as your {id} or possibly a Request.QueryString parameter from the URL, or an HTTP header or cookie), the Model will know how to reach out to your existing business logic classes and build up itself for rendering by the View.
e.为模型创建构造函数类,以便给定控制器将具有的某些参数(作为您的{id}或可能的请求传入)。通过URL的QueryString参数,或者HTTP头或cookie),模型将知道如何访问您现有的业务逻辑类,并通过视图构建自己来呈现。
f. Go to next page in the list and start again from step a.
f.到列表的下一页,从步骤a重新开始。
-
Finally create the routing rule that will call your new Controller and allow the Actions you have written to be implemented. Debug, debug, debug...Once you're happy all is well, remove the existing folder and files you've migrated from your main site, as well as the IgnoreRoute rule in the global.asax.cs.
最后创建路由规则,该规则将调用您的新控制器并允许实现您编写的操作。调试、调试,调试……一旦你觉得一切都很好,就删除你从主站点迁移的现有文件夹和文件,以及global.asax.cs中的IgnoreRoute规则。
-
Create a redirect in whatever manner you prefer if you wish to preserve old directory and file names for continuity (e.g. users may have bookmarked certain pages in the old site already).
如果您希望保存旧目录和文件名以保持连续性(例如,用户可能已经在旧站点中添加了书签),那么可以以任何您喜欢的方式创建重定向。
Note: If you are keeping the exact names of the old subdirectories in your MVC site during the porting phase, it's preferable to migrate a whole subdirectory at a time I've realised, because by only doing a few files the routing rules you need to write become more complex since if an existing folder exists with the same name as a routing rule's path and that folder has a Default.aspx file then (/foldername/) will default to the Default.aspx page, as it takes precidence over the routing rules.
注意:如果你保持旧的确切名称的子目录在你的MVC网站在移植阶段,最好的方式还是迁移整个子目录的时候我意识到,因为只做几个文件路由规则需要编写更复杂的因为如果现有的存在具有相同名称的文件夹作为路由规则有一个默认的路径和文件夹。然后aspx文件(/foldername/)将默认为默认值。aspx页面,因为它对路由规则非常精确。
Tip: Seriously consider using a tool like RouteDebug for route debugging so you can figure out strange things like above, or when you have multiple routing rules firing and causing unexpected behaviors.
提示:请认真考虑使用RouteDebug之类的工具进行路由调试,这样您就可以解决上面提到的奇怪问题,或者当您有多个路由规则触发并导致意外行为时。
This is my first draft, please give me feedback if I've missed any steps or if you see any holes in the guide, and I'll modify the answer appropriately.
这是我的初稿,如果我漏掉了任何步骤,或者你在指南中看到任何漏洞,请给我反馈,我会适当修改答案。
#2
2
I don't think there is such a thing as a "step-by-step migration" from ASP.NET WebForms to ASP.NET MVC. They are two completely different design patterns built on the same framework, but there are (in most cases) a lot of things that need not only to be moved, but completely re-designed, if you don't just want to build a web app on the MVC template project instead of the WebForms template.
我不认为存在从ASP“逐步迁移”这样的事情。净WebForms ASP。净MVC。他们是两个完全不同的设计模式建立在相同的框架,但有(在大多数情况下)很多东西,不仅需要移动,但是完全重新设计的,如果你不只是想要构建一个web应用程序的MVC项目模板的WebForms模板。
The main reason for this is the separation of concerns, which is much stricter in MVC than in WebForms. I am currently working (well, I should be...) on migrating an old and pretty buggy hobby-project from WebForms to MVC and my approach has basically been "look at the functionality, re-build it from scratch." Of course I had some helper methods for formatting output etc that I just included in my new project, but most of the basic stuff I chose just to redo completely. You'd be surprised how little it takes me to reach the same goals with MVC now, that I set up for the WebForms app a year-and-a-half ago - with the use of Entity Framework, jQuery and other sweet stuff, you'll be able to produce results within a couple of hours.
这样做的主要原因是关注点分离,这在MVC中比在WebForms中更加严格。我现在正在工作(嗯,我应该是…),从WebForms迁移到MVC,我的方法基本上是“看一下功能,从头重新构建它”。当然,我在新项目中包含了一些格式化输出的辅助方法等,但是我选择的大部分基本方法都是完全重做。你会惊奇地发现,我现在用MVC实现相同的目标是多么的少,我在一年半前就为WebForms应用设置了这个应用——使用实体框架、jQuery和其他的sweet stuff,你将能够在几个小时内产生结果。
#3
2
May these few additional tips will assist
这些额外的技巧能帮上忙吗
- Replace <%-- comment tags with @*
- 以@*替换<%——注释标签。
-
use @RenderSection("Footer",false) for @section footer { } and so on,if you have any additional ContentPlaceHolder except the main body in View which RenderBody() .
对于@section Footer{}等,可以使用@RenderSection(“Footer”,false),如果您有任何额外的ContentPlaceHolder,除了RenderBody()视图中的主体之外。
-
all the old normal runat="server" tags are harmless and do not prevent compile and can be cleaned afterwards
所有旧的常规runat=“server”标记都是无害的,不会阻止编译,可以在编译之后进行清理
-
all controls Visibility which was easily controlled in code behind and markup (Visible="True") and controlled in code_behind by use of Control Id must be refactored to ViewBag Collection and @if blocks in Razor view.
所有控件的可见性在代码后和标记(Visible="True")中很容易控制,并且在code_behind中通过使用控制Id进行控制,必须重构为ViewBag集合和Razor视图中的@if块。
-
you can also watch this excellent course of Pluralsight around this topic (3h 49m)
你也可以在这个主题(3h 49m)中观看这一精彩的过程。
- Rebuilding Web Forms Applications in MVC
- 在MVC中重新构建Web表单应用程序
#4
1
My answer would be "You don't" :). If you really want to do this, you can use the current asp.net site as your end goal, or as a requirements 'document'. And maybe you can use the datalayer in your model, but you'll have to redesign the whole site.
我的回答是“你不知道”。如果您真的想这样做,您可以使用当前asp.net站点作为您的最终目标,或者作为需求文档。也许你可以在你的模型中使用datalayer,但是你必须重新设计整个网站。
As Tomas already pointed out, it's VERY different from classic asp.net.
正如托马斯已经指出的,它与传统的asp.net非常不同。
#1
67
These is my step-by-step guide, based on steps we have taken at my company during our move from a classic ASP.Net Webforms to ASP.Net MVC. It's not perfect, and still ongoing since we have to do this in stages because of the size of the site, but perhaps someone else will find and file an improved answer based on our results.
这是我的一步一步指导,基于我们在公司从一个典型的ASP中所采取的步骤。净Webforms ASP。净MVC。它并不完美,而且还在进行中,因为由于站点的大小,我们必须分阶段进行,但是也许其他人会根据我们的结果找到并提交一个改进的答案。
Stages: 1. Planning - moving to MVC from Web Forms in ASP.Net requires some careful planning. The mistake we made in our move is not realising that there are are really two aspects to this stage of planning, route planning and model/controller/action planning. Not doing this will cause serious issues later on as you try to extend functionality of your site or hit more complex migrations.
阶段:1。规划——从ASP中的Web表单迁移到MVC。Net需要一些仔细的计划。我们在行动中犯的错误是没有意识到,在计划、路线规划和模型/控制器/行动计划这一阶段实际上有两个方面。当您尝试扩展站点的功能或进行更复杂的迁移时,不这样做将导致严重的问题。
Tips: - Look at your current sitemap, and design the improved sitemap/directory structure to be used in the ASP.Net MVC application. Figure out a 'language' for your website, e.g. the default behaviour of ASP.Net MVC is to have a http://sitename/{controller}/{action}/{id} behavior, but you can override this as you gain more experience hacking routing rules.
提示:-查看您当前的站点地图,并设计改进的站点地图/目录结构将在ASP中使用。净MVC应用程序。为你的网站找出一种“语言”,例如ASP的默认行为。Net MVC将具有http://sitename/{controller}/{action}/{id}行为,但随着您获得更多破解路由规则的经验,您可以重写此行为。
-
Remember by default each Controller will be routed to via a virtual subdirectory of your application, e.g. http://sitename/X would route to XController (and by default its Index method), http://sitename/Y/Get would route to YController's Get() method. You can change this as you please (routing's really powerful), but that's beyond the scope of this answer.
记住,默认情况下,每个控制器都将通过应用程序的一个虚拟子目录被路由到,例如http://sitename/X将路由到XController(默认情况下是它的索引方法),http://sitename/Y/Get将路由到YController的Get()方法。您可以随意更改它(路由非常强大),但这超出了这个答案的范围。
-
Using the existing sitemap, specify what folder in the MVC structure each current .aspx page should fall (of course, first ask if it should exist at all).
使用现有的sitemap,指定MVC结构中每个当前的.aspx页面应该放置的文件夹(当然,首先要问它是否应该存在)。
-
If Scripts, Images etc are not stored together, or in some 'reserved name' folders within each subdirectory, consider doing so now as you're redesigning. This is as it would greatly simplify your design by allowing you to use a Map.IgnoreRoute() routing rule command in the Global.aspx.cs file to bypass processing these folders as routes.
如果脚本、图像等没有存储在一起,或者在每个子目录中的某个“保留名称”文件夹中,请在重新设计时考虑这样做。通过允许您在Global.aspx中使用Map.IgnoreRoute()路由规则命令,可以大大简化设计。cs文件绕过处理这些文件夹作为路由。
In our case we mirrored the real subdirectory layout of the current site, where each subdirectory became a controller, e.g. /Account would have an AccountController, /X would have XController. All pages that fell inside there were replaced by actions within each Controller. e.g. http://sitename/profile/about.aspx now became http://sitename/profile/about and mapped to the "about" ActionResult method inside the profileController. This is allowing us to stay agile by doing a partial migration of one or two directories (or several files inside one directory) over a series of sprints, rather than having to migrate the entire site in one go over a much longer duration.
在我们的例子中,我们反映了当前站点的实际子目录布局,其中每个子目录成为一个控制器,例如,/Account将有一个AccountController, /X将有XController。所有位于其中的页面都被每个控制器中的操作所取代。例如,http://sitename/profile/about。aspx现在变成了http://sitename/profile/about并映射到profileController的“about”ActionResult方法。这允许我们通过在一系列的sprint中进行一两个目录(或者一个目录中的几个文件)的部分迁移,而不是在一段时间内迁移整个站点,从而保持敏捷。
-
Create a new ASP.Net MVC application in Visual Studio and immediately create the rules in the Global.asax file that ignore routing rules for the folders that exist in the current site.
创建一个新的ASP。Net MVC应用程序在Visual Studio中,并立即在全局中创建规则。忽略当前站点中存在的文件夹的路由规则的asax文件。
-
Copy the folders from the ASP.Net Web Application to the ASP.Net MVC Application folders. Run the website and ensure it works properly (it should as no routing rules are being used yet).
从ASP拷贝文件夹。Net Web应用程序到ASP。净MVC应用程序文件夹。运行网站并确保它正常工作(它应该还没有使用路由规则)。
-
Pick a subdirectory or subset of files within a subdirectory to migrate.
选择一个子目录或子目录中的文件子集来迁移。
-
For each .aspx page inside this subdirectory:
对于本子目录中的每个.aspx页面:
a. Create its View first. I tend to use the web-browser rendered version of the page as my base HTML, and then put placeholders in the locations that I know are filled with dynamic data.
首先创建视图。我倾向于使用web浏览器渲染的页面版本作为我的基本HTML,然后在我知道充满动态数据的位置放置占位符。
b. Using the placeholders for the dynamic data, create a first-draft of the Model using simple data types. This model will start off simple, but be constantly refactored as you migrate more pages from the original site, so don't worry if it starts looking a little heavy. If you find yourself with too many Properties in one Model for your taste, or see a logical grouping beyond just the Model of certain subset of items, perhaps this is a sign the Model needs to be refactored to have an object instead with these simple data types as properties but is composed in the business logic layer.
b.使用动态数据的占位符,使用简单的数据类型创建模型的初稿。这个模型一开始很简单,但是当您从原始站点迁移更多的页面时,会不断地重构它,所以如果它看起来有点重,不要担心。如果你发现自己有太多的属性在一个模型你的口味,或看到一个不仅仅是逻辑分组模型项目的某些子集,也许这是一个信号模型需要重构对象而不是与这些简单的数据类型属性,但在业务逻辑层组成。
c. Create the controller if it hasnt been created yet, and put the appropriate ActionResult method for the Action your planning has determined should route to this view. If you realise something that there is a new action that doesn't map to a page from the old site, then create the View for the controller, and include appropriate //TODO: tags so you can keep track of this to implement after you have migrated the existing pages.
c.如果还没有创建控制器,就创建它,并为您的计划确定的应该路由到该视图的操作放置适当的ActionResult方法。如果您意识到有一个新动作没有映射到来自旧站点的页面,那么为控制器创建视图,并包含适当的//TODO:标记,以便在迁移现有页面之后跟踪该动作以实现。
d. Consider putting in some handling code for unknown actions as well, if you don't have a {*catchall} Routing rule for this already in your global.asax.cs file.
d.如果您没有在您的global.asax中已经有这样的{* *catch - all}路由规则,那么考虑为未知操作输入一些处理代码。cs文件。
e. Create the constructor classes for the Model so that given certain parameters that the Controller will have (passed in as your {id} or possibly a Request.QueryString parameter from the URL, or an HTTP header or cookie), the Model will know how to reach out to your existing business logic classes and build up itself for rendering by the View.
e.为模型创建构造函数类,以便给定控制器将具有的某些参数(作为您的{id}或可能的请求传入)。通过URL的QueryString参数,或者HTTP头或cookie),模型将知道如何访问您现有的业务逻辑类,并通过视图构建自己来呈现。
f. Go to next page in the list and start again from step a.
f.到列表的下一页,从步骤a重新开始。
-
Finally create the routing rule that will call your new Controller and allow the Actions you have written to be implemented. Debug, debug, debug...Once you're happy all is well, remove the existing folder and files you've migrated from your main site, as well as the IgnoreRoute rule in the global.asax.cs.
最后创建路由规则,该规则将调用您的新控制器并允许实现您编写的操作。调试、调试,调试……一旦你觉得一切都很好,就删除你从主站点迁移的现有文件夹和文件,以及global.asax.cs中的IgnoreRoute规则。
-
Create a redirect in whatever manner you prefer if you wish to preserve old directory and file names for continuity (e.g. users may have bookmarked certain pages in the old site already).
如果您希望保存旧目录和文件名以保持连续性(例如,用户可能已经在旧站点中添加了书签),那么可以以任何您喜欢的方式创建重定向。
Note: If you are keeping the exact names of the old subdirectories in your MVC site during the porting phase, it's preferable to migrate a whole subdirectory at a time I've realised, because by only doing a few files the routing rules you need to write become more complex since if an existing folder exists with the same name as a routing rule's path and that folder has a Default.aspx file then (/foldername/) will default to the Default.aspx page, as it takes precidence over the routing rules.
注意:如果你保持旧的确切名称的子目录在你的MVC网站在移植阶段,最好的方式还是迁移整个子目录的时候我意识到,因为只做几个文件路由规则需要编写更复杂的因为如果现有的存在具有相同名称的文件夹作为路由规则有一个默认的路径和文件夹。然后aspx文件(/foldername/)将默认为默认值。aspx页面,因为它对路由规则非常精确。
Tip: Seriously consider using a tool like RouteDebug for route debugging so you can figure out strange things like above, or when you have multiple routing rules firing and causing unexpected behaviors.
提示:请认真考虑使用RouteDebug之类的工具进行路由调试,这样您就可以解决上面提到的奇怪问题,或者当您有多个路由规则触发并导致意外行为时。
This is my first draft, please give me feedback if I've missed any steps or if you see any holes in the guide, and I'll modify the answer appropriately.
这是我的初稿,如果我漏掉了任何步骤,或者你在指南中看到任何漏洞,请给我反馈,我会适当修改答案。
#2
2
I don't think there is such a thing as a "step-by-step migration" from ASP.NET WebForms to ASP.NET MVC. They are two completely different design patterns built on the same framework, but there are (in most cases) a lot of things that need not only to be moved, but completely re-designed, if you don't just want to build a web app on the MVC template project instead of the WebForms template.
我不认为存在从ASP“逐步迁移”这样的事情。净WebForms ASP。净MVC。他们是两个完全不同的设计模式建立在相同的框架,但有(在大多数情况下)很多东西,不仅需要移动,但是完全重新设计的,如果你不只是想要构建一个web应用程序的MVC项目模板的WebForms模板。
The main reason for this is the separation of concerns, which is much stricter in MVC than in WebForms. I am currently working (well, I should be...) on migrating an old and pretty buggy hobby-project from WebForms to MVC and my approach has basically been "look at the functionality, re-build it from scratch." Of course I had some helper methods for formatting output etc that I just included in my new project, but most of the basic stuff I chose just to redo completely. You'd be surprised how little it takes me to reach the same goals with MVC now, that I set up for the WebForms app a year-and-a-half ago - with the use of Entity Framework, jQuery and other sweet stuff, you'll be able to produce results within a couple of hours.
这样做的主要原因是关注点分离,这在MVC中比在WebForms中更加严格。我现在正在工作(嗯,我应该是…),从WebForms迁移到MVC,我的方法基本上是“看一下功能,从头重新构建它”。当然,我在新项目中包含了一些格式化输出的辅助方法等,但是我选择的大部分基本方法都是完全重做。你会惊奇地发现,我现在用MVC实现相同的目标是多么的少,我在一年半前就为WebForms应用设置了这个应用——使用实体框架、jQuery和其他的sweet stuff,你将能够在几个小时内产生结果。
#3
2
May these few additional tips will assist
这些额外的技巧能帮上忙吗
- Replace <%-- comment tags with @*
- 以@*替换<%——注释标签。
-
use @RenderSection("Footer",false) for @section footer { } and so on,if you have any additional ContentPlaceHolder except the main body in View which RenderBody() .
对于@section Footer{}等,可以使用@RenderSection(“Footer”,false),如果您有任何额外的ContentPlaceHolder,除了RenderBody()视图中的主体之外。
-
all the old normal runat="server" tags are harmless and do not prevent compile and can be cleaned afterwards
所有旧的常规runat=“server”标记都是无害的,不会阻止编译,可以在编译之后进行清理
-
all controls Visibility which was easily controlled in code behind and markup (Visible="True") and controlled in code_behind by use of Control Id must be refactored to ViewBag Collection and @if blocks in Razor view.
所有控件的可见性在代码后和标记(Visible="True")中很容易控制,并且在code_behind中通过使用控制Id进行控制,必须重构为ViewBag集合和Razor视图中的@if块。
-
you can also watch this excellent course of Pluralsight around this topic (3h 49m)
你也可以在这个主题(3h 49m)中观看这一精彩的过程。
- Rebuilding Web Forms Applications in MVC
- 在MVC中重新构建Web表单应用程序
#4
1
My answer would be "You don't" :). If you really want to do this, you can use the current asp.net site as your end goal, or as a requirements 'document'. And maybe you can use the datalayer in your model, but you'll have to redesign the whole site.
我的回答是“你不知道”。如果您真的想这样做,您可以使用当前asp.net站点作为您的最终目标,或者作为需求文档。也许你可以在你的模型中使用datalayer,但是你必须重新设计整个网站。
As Tomas already pointed out, it's VERY different from classic asp.net.
正如托马斯已经指出的,它与传统的asp.net非常不同。