Pergunta

Have one Doubt In MVC Architecture we can able to pass data from Controller to Directly view without creating strongly typed view, than why there is need to use Models ..?

Is it decreases the Performance of the application if we are saving data in ViewData[""] and use it in Views to display Information . . ?

Foi útil?

Solução

Storing data in a collection (ViewData) technically will be ever so slightly slower than passing in a strongly typed model (concrete class), but the difference is extremely small. There is also a tiny increase to the memory footprint (because you need memory for the collection and for the thing(s) in the collection) but again, that should be inconsequential.

Strongly typed models provide a clear contract between the controller and the view. I prefer them in all cases personally.

There can be simple views where the developer feels it unnecessary to create a strong type to represent the controller/view contract. For that need, ViewData exists.

I imagine that ViewData is also used by some to pass extra data not originally envisioned in the strongly typed model. I would encourage refactoring the strong type in such cases rather than passing extra data in ViewData.

There may be "legitimate" uses of ViewData that I'm missing, but I have not come across any thus far.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top