1. Preface
I am reading a study, and my teacher is using ASP. NET Web Forms technology. I really want to say: Nima is too old! I have heard of Python's efficient development and have learned a little about Python's Django framework. This is the first time I came into contact with the MVC model. After returning to the. NET platform, ASP. net mvc naturally became my first choice for learning. I have spent some time learning Bootstrap to easily create web pages. When I found ASP. net mvc 5 integrated with Bootstrap, I was ecstatic and decided to choose MVC5.
2. Basic MVC pattern Diagram
/[Controller]/[ActionName]/[Parameters]
Of course, you can customize the route logic by modifying the App_Start/RouteConfig. cs file, for example:
(2) Return Value Type of Action MethodAfter the action method is called, the return value type can be string, so that the string is directly output to the browser in hard-code mode.
You can also return a View object, which uses a View template to generate an HTML response to the browser. Generally, ActionResult or its derived type is returned, rather than a string.
(3) passing data or objects to a view TemplateYou can use ViewBag when passing parameters from a controller to a view template. ViewBag is a dynamic object. We can put any information into it. There will be no defined attributes before we put the data in.
MVC also supports passing strong-type objects. This type of strong-type method enables better code check during compilation and more abundant intelliisense functions in the Visual Studio editor.
(4) database environment inherited from DbContext (Context temporarily translated as Environment)In the cs file that defines the model class, an object environment class is also defined. This class represents the Entity Framework database environment, which is used to process the addition, deletion, modification, and query of model class instances in the database. This class is derived from the DbContext base class provided by Entity Framework.
(5) Create a database connection stringThe connection string of the database specifies the database to use. Entity Framework uses LocalDB by default (a lightweight SQL Server Express database engine ). By default, Entity Framework looks for a connection string with the same name as the object environment class.
You can manually add a connection string to the Web. config file in the application root directory. Add the following to the <connectionStrings> label:
We do not need to add the above connection string. If we do not specify a connection string, Entity Framework will create a LocalDB database using the fully qualified name of DbContext in the user directory. We can name the database as long as it is suffixed with. MDF.
3. Postscript
My younger brother is a cainiao and is interested in ASP. NET and Python. It is a pity that I have a strong sense of study and I have no colleagues or friends who can communicate with me. If any of you are willing to discuss with me, please kindly advise. My email isName.wuzhiyu@outlook.com.