如何在mvc中的每个文件夹下添加我的逻辑 [英] How to add my logic under each folder in mvc

查看:99
本文介绍了如何在mvc中的每个文件夹下添加我的逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ASP.Net MVC的新手。我打算在网站上创建分类广告。



所以我想得到以下网址

I am very new to ASP.Net MVC. I am planning to create on website for classifieds.

So I would like to get url as following

(http://mysitename.com/stateName/Place/Furniture/34)







从管理面板我应该能够创建StateName,Place,Category (例如家具)







我打算将它作为实体的代码优先方法启动框架。





?哪一个都是我必须创建的控制器

?我必须在模型中创建什么数据

?我可以在项目下创建文件夹以保留地点和类别





因此,请引导我使用您宝贵的建议创建此应用程序。



先谢谢。




From admin panel I should able to create StateName,Place, Category(eg. Furniture)



I am planning to start it as code-first approach of Entity Framework.


? Which all are the controllers i have to create
? What data I have to create inside model
? Can I create Folders under the project to keep Place and Category


So please guide me to create this application with your valuable suggestion.

Thanks in Advance.

推荐答案

你出去学习很多东西。所以最好的学习MVC。 :)



1-现在您对问题的疑问,我们无法为您提供此项目的整个架构。但请记住学习和实现架构,以便项目松散耦合,以便易于维护,不仅适用于您将来执行的任何项目的此项目。



2 - 当您选择并创建一个带有名称的新ASP.NET MVC项目时,它会创建一个包含Web项目(MVC项目)的解决方案。



3 - 那个项目将有Model Controller&已查看文件夹。除此之外,Web项目将包含App_Start,Filters文件夹,Global.asax(Web项目的开头或核心)和Web.config,其中所有数据库的连接字符串和所有应用程序配置都将在那里。 />


4 - 根据您的要求,您应该在解决方案中创建另一个项目并命名为您的项目名称。核心,其中包含所有数据库的enitity / classes,因为您将使用Code first方法,然后您将创建的所有enitity类将位于此项目内的名为Entities的文件夹中。在这个项目中,迁移也将完成。因此,Web项目将不依赖于域实体或Db操作。对于此跟进,请执行以下操作: - ASP.NET MVC控制器依赖关系初学者注入 [ ^ ]



5 - 将第三个问题放在项目下的地方和类别。为此,我认为这应该是数据库中的表,因此在Core内部创建类。您应该将Web项目主要用于演示目的。模型文件夹应该包含用于演示文稿/视图页面的视图模型或模型/ .cs文件。



我希望你得到我想解释的内容。

发回任何疑问。

希望这会有所帮助。

谢谢。
You are out for learning a lot of things. So all the best for learning MVC. :)

1- Now for your queries in the question, we cannot provide you the entire architecture for this project. But keep in mind to learn and implement the architecture so that the project is loosely coupled so that it would be easy for maintainability, not only for this project for any project you do in future.

2-When you choose and create a new ASP.NET MVC project with a name, it creates a solution with a web project (MVC project) in it.

3-That project will have Model Controller & Views folder already. Other than these, the web project will have App_Start, Filters folder, Global.asax(Start or heart of the web proj.) and Web.config where all the connection strings to the database and all the Application Configurations will be there.

4-For your requirements, you should create another project inside the solution and name as "YOUR PROJECT NAME.Core", which will contain all the database enitity/classes, since you will be using Code first approach, then all the enitity classes you will be creating will be inside this project inside a folder named "Entities". In this project the Migrations will also be done. So, that the Web Project will not be dependent on the Domain Entities or the Db operations. For this follow up this like:- ASP.NET MVC Controller Dependency Injection for Beginners[^]

5-Your third question to place folder under the project for Place and Category. For this I think this should be table inside the database so create classes inside the Core. You should use the Web Project mostly for the presentation purposes. Model folder should contain the View Models or the Models/.cs files used for the presentation/viewpages.

I hope you get what I wanted to explain.
Post back any queries if any.
Hope this helps .
Thanks.


这篇关于如何在mvc中的每个文件夹下添加我的逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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