ASP.NET MVC strongly typed representations or not?

What is the best practice is to use only strongly typed views without any parameters that go through the ViewData dictionary, or a good idea is to use something like this in the view:

<%: (string)ViewData["helloMessage"]%>

Thank.

+3
source share
2 answers

You should prefer strongly typed views. In some cases, you only need one line, as in your example, which is not related to the model, then it can be used. Another way is to encapsulate this variable in a class and pass the class to the view. The result will be a strongly typed representation :-)

I personally don't like magical strings.

+6
source

" " ​​
.

MVC 3 ViewModel , View in view.
, ViewModel.MyData="something"; @View.MyData
.

.
.
.

+1

Source: https://habr.com/ru/post/1777435/


All Articles