且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我需要MVC的基本指导

更新时间:2023-02-09 09:43:33

由于您的帖子中不清楚您是否了解MVC的概念,因此我可以基本了解什么是MVC。



虽然从MVC模型开始看起来很复杂,但是在理解主要概念时很容易习惯它。



1.模型:可以有两种类型 - 模型和模型视图。模型可以是您的业务实体或等同于数据库表。 ModelViews将在您的视图中使用。它可以在任何视图中用作单个实体的任何模型组合。例如,假设视图中有两个网格,每个网格都由一个模型表示。模型视图将这两个实体合并为一个(一个单独的类,这两个实体作为成员)。主要目的是在控制器和视图中更轻松地移植它。假设您知道如何维护数据模型(类),没有什么可学的。



2.查看 - 所有aspx页面(就webforms而言)都是视图。视图可以基于aspx语法或Razor语法。 Razor语法更适合使用,因为它遵循简单的结构并且易于解开。项目中的每个页面都与视图相关。基本上,view使用基本的html控件(html5),因此很容易理解这部分内容。



3.控制器 - 模型对它们进行各种操作并生成结果(可能在ModelView中)并将其抛出到视图中使用基本HTML控件来显示值。 Controller基本上是一个类(.cs),带有称为actions的特殊方法。当一个请求被发送到asp.net MVC时,它被传递给动作,动作对模型进行一些处理,并将结果模型/ modelView返回到视图,语法如下return View(MyModelView);.选择视图由asp.net路由根据名称自动生成。如果您的请求是http; // abc.com/Customer/list。在Customer控制器列表操作下,基本上返回名为List的视图。



除了关注点和可维护性之外,我更喜欢MVC而不是webforms,主要是为了避免使用webforms的完整服务器控件以及与UI问题的交易。



Google搜索asp.net MVC将为您提供大量有关如何入门的文章和教程。



如果您有任何具体问题,请与我们联系。



其他专家,我是Code项目的新手,如果我在上面的故事中犯了任何错误,请纠正我,提前谢谢。
Since it is not clear in your post whether you know the concepts of MVC, I can give a basic insight on what is MVC.

Though it looks complex to start with MVC model being a webforms developer, it is very easy to get accustomed to it upon understanding the main concepts.

1. Model: There can be two types - Models and ModelViews. Models can be your business entity or equivalent to database tables. ModelViews are to be used inside your views. It could any combinations of models to be used as a single entity within any view. Example, imagine you have two grids in a view each is represented by a model. Model view holds these two entities into one (a seperate class with these two entities as memebers). Main purpose is to port it easier across controller and view. There is nothing much to learn assuming you know how to maintain the data models (classes).

2. View - All aspx pages (in terms of webforms) are views. Views can be based on aspx syntax or Razor syntax. Razor syntax is more advisable to be used as it follows simple structure and easy to undserstand. Each page in your project is related to a view. Basically view uses basic html controls (html5) so it is easy to understand this part.

3. Controller - It takes the models do all sorts of operations on them and produce a result (possibly in ModelView) and throw it to the view, which in turns uses basic HTML controls to display the values. Controller is basically a class (.cs) with special methods called "actions". When a request is sent to asp.net MVC it is passed to the action and the action does some processing on the models and returns the resulting model/modelView to the view with syntax like this "return View(MyModelView);. Views are chosen automatically by the asp.net routing based on the name. If your request is "http;//abc.com/Customer/list. Under Customer controller list action is called and a view with the name List is returned basically.

Apart from separation of concerns and maintainability I prefer MVC over webforms mainly to avoid using complete server controls of webforms and the dealings with their UI issues.

Googling "asp.net MVC" will fetch you plenty of articles and tutorials on how to start with.

Please let me know if you have any specific questions.

Other experts, I am new to Code project, please correct me if I made any mistakes in the above story, Thanks in advance.

>

也许您可以尝试ASP.NET MVC网站: http://www.asp.net/mvc [ ^ ]。
Maybe you can try the ASP.NET MVC website: http://www.asp.net/mvc[^].