ASP.NET MVC best practice?

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
July 8th 19 at 11:32
3 answers
July 8th 19 at 11:34
Solution
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.
3)This is not a problem. No one will prevent you to write Javascript logic, which later in the process, take data through the API itself will draw view. Do as you want, but it should be readable, and support a little to fit the task at hand( no need to use Angular just to use Angular)
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).
6)maybe, Maybe not. Again - the client side you can sculpt different methods. Can and Javascript. In ASP.NET it is not forbidden. It is never forbidden.
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.
END UPD.
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.
1 - Yes mean readability
4 - Under the shortest - mean that it should not be try-catch with logging for example, or safety logic or some debug information (profilacy memory and time for example).
5 - the reason for the appearance of this item, performance - an extra request to the server, if you can validate some part of data on the client, why not check out. no?
7 - had in mind about the replacement of the default binder. the standard solution - in controller method comes entity id, look for it in the repository by id. I'm too lazy to write in each method an id, I want for me, it makes binder (the thing which substitutes the value of the controller argument when requesting), in short, for the resolving of complex objects easier to write your binder, rather than hostility default
8 - In the context of composite types: possible, but not necessary for the model to use ViewBag? At the moment sees that it is only for shoes, but if there is code that uses it to transfer the model, the developer of this code should dime line on fingers.
9 - Yes, XmlHttpRequest. When the same element is used and Ajax.Forms and XmlHttpRequest.
Let's say a table, say table with pagination. Let's say each row has a cell in which there is an expander, by clicking on the expander needs to load data from the server. Doing pagination using Ajax form, download by clicking on the expander using a naked Ajax. I think one that one file, in one element both in hard pobyut readability?
10 - Well, damn, there must be some accepted standard in the ASP.NET. Really develop someone in that much? Ie I went to one company, doing all the layout and try to separate the markup on PartialView for reuse. Then I went to another company, and then through Js draw a layout and have to get used again? - kody.Kuhn commented on July 8th 19 at 11:37
PS: thanks for UPD in 6 points, that's what I meant. - kody.Kuhn commented on July 8th 19 at 11:40
4) Logging using IoC containers can and should be done where there is a need for logging. At the controller level we operate with the status of the request - of course log error-level business logic at the controller level is not necessary. Security logic can be done via the attributes controller method.
5) Well, and save on it. But if server-side validation should be required, the client is already optional.
7)For me, the binding entities were never really troubled. For GET request you can pass the ID to pull data from the repository. For changes and additions I like to bindigirl model class, not a set of input parameters to design the object.
8)A basic task is to drag the model object in the View to render. If you need to drag some related data that also need to render a View(some dictionaries, additional collection, etc.) - then create a new model class and shove all you need. The original model will be just a new class. ViewBag suitable to forward messages like "All is well" or "Everything is broken - that's the reason".
9) Well, Yes, in my opinion such an expander is better to pull in a separate PartialView.
10) I will upset you, Yes, it is. Good you should be able to use different tools or at least be willing to learn new. Imagine what I'll do to ofer to the company. The pay is good, the project is interesting and challenging, all white, beautiful, but the problem is, the draft half written in Web Forms, the second at the zoo ASP.NET MVC and what will be new projects is unknown. Good, solid project usually works for 8-10 years or more. During this time, a lot going on and a tool used in the 2007th, as the best of its kind, can look terrifying in 2016. Try to fit it to the management and say that after six months you will rewrite the entire project into an elegant technology, and he will hear what you are going to spend 0.5-1.5 million rubles and the output will get what he has(this is a variation on a recent report from Dino Esposito, but not my experience). - glenna_Hauck commented on July 8th 19 at 11:43
: Thank you. - kody.Kuhn commented on July 8th 19 at 11:46
July 8th 19 at 11:36
Solution
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.
Thank you. - kody.Kuhn commented on July 8th 19 at 11:39
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.
5. Yes.
6. Legs kicking, no one will, I guess, but damn, the principle of separation of responsibility has not been canceled.
7. Use ViewModel.
8. No.
9.

Find more questions by tags .NETASP.NETC#