Good day. Study ASP.NET MVC 5. In a professional environment asp.net'pins do not have, so I have to go here. During the study materiel made for myself some conclusions about the proper use of this technology. I need to verify the correctness of the conclusions. Below is the list of statements on each item which please put in the replies +/- or combing comments. Of course all claims for any average case, an average project of medium complexity with "average" requirements.
1) the Routes should be as short as possible
2) Install routes using RouteConfig preferable to routing via attributes (or in some cases, you should use all the same attributes)?
3) Forms and HTML elements generated possibly using the HtmlHelper
4) Methods of action should be as short as possible. The logic of validation, authentication, error handling needs to be in third-party classes and connect using attributes
5) data Validation must happen on the client side (JQuery) and server-side
6) In the view should be only support c# code to build the layout. And this code should be minimal
7) To CRUD the entities use custom binders, instead of the method signature action of the form: void Action(int entityId);
to have the signature of the form: void Action(Entity currentEntity);
since the standard binder for signatures void Action(Entity currentEntity);
every time you create a new instance of the Entity
8) ViewBag - crutch to be used only in simple cases (approx. the transfer of the title in the page)
9) Ajax-form rather than a naked Ajax. If one view suggests both approaches, the view should be refactored
10) All that can be done in markup by using the Razor, must be done with a Razor
I'm certainly no guru, but I'll try to voice my opinion.
1)In General - Yes. But what do the short route? a short word or a small number of slashes? It's all the same swing readability nearby.
2)I think Yes and the reason is quite simple - I don't want to climb around the project to find out why this route fell into this controller. But there is an exception - regions(Areas). They have your RouteConfig and it is possible that it will work perfectly from the default.
4) Then you're in a heap of mixed. The shortest? In principle, Yes, but I would read the title to figure out exactly what he was doing, not to see the surprise later. The rest also agree.
5) Suppose it is needed. Firstly remove the word JQuery - this is the library for validation has little relevance. The second server is usually enough inspections of properties ModelState.isValid or Model.isValid. Of course if your model is marked with all the attributes bounding the correct values. Here, however, there is one little problem - suppose you have changed the logic of validation(field has been updated or even some movements done). In practice, you have two places to update the same logic that is not quite correct(potential code duplication, potential errors of forgetfulness).
UPD:Programming in C# inside a View is not necessary. To pull extra data as well, though occasionally the need arises(dictionary of some drag). Basically the code should contain functions for example to generate some line or check the status of an object by multiple fields instead of writing a bunch of if in the markup.
7)If you honestly do not understand what you mean.
8)It's not a crutch, it is a transport system for short messages, and simple types. To use as transport for the model is also possible, but not safe from the point of view of casting.
9) what do you mean by "naked Ajax"? XmlHttpRequest? Yes, in my opinion better not to use it. The second part of the question will not be able to comment without answering the first. Views are different, some pull additional data along the way. Then you need some specifics.
10) do Not agree and have voiced earlier. Razor one of the available tools. Can use it - it is good, but can not use.
florencio.Abernathy answered on July 8th 19 at 11:36
1. In this project, the routes will be thinking SEO.
2. Yes. The attributes of the litter code, harder to find, it is better to keep in one place. Anyway in terms of attributes, it is better to use less of them, first think over all the options with no attributes and only in the end to compare and evaluate their usefulness.
3. Well, here it's better than writing naked HTML, although in the end will be heavier.
4. Consider the attributes of evil. Is that as simple as possible should be, Yes, try to use standard mechanisms, if you need to return Json, use JsonResult (although in particular case, its features may not be enough, but only in this case you should use something else). And of course the logic needs to be separated and be independent from the web, to know nothing about the web, etc.
5. On the client side, optionally on the server side, compulsory and compulsive. To come may all.
6. True, only the code which is responsible for displaying and no logic.
7. Well your binder to do is, if you do not have a standard mechanism, but do not, you still have to create a new object.
8. It is better never to use, harder to understand the code, complicate the search for errors etc. Then the situation is of course much depends. But I would have done either through aggregation or inheritance. It is possible to service or even as a thread.
9. I do not quite understand generally what you mean.
10. Well it all depends on the template engine, and not the Razor to use. nobody forbids.
Lee.Runolfsson answered on July 8th 19 at 11:38
1 and 2 already answered.
3. Better on the side of the front of the SPA. Razor is a powerful templating engine, but....
4. Yes, it is normal practice.
6. Legs kicking, no one will, I guess, but damn, the principle of separation of responsibility has not been canceled.
7. Use ViewModel.