Model view controller: shall the view know custom data types? -
very simple question: in strict mvc design pattern want keep model, view , controller can view layer know custom data classes defined in model?
as example:
i got carviewcontroller in view layer , car object in model layer. whenever model layer changes controller object "sits" between model , view notifies carviewcontroller , in current implementation passes copy of updated car data instance of car class. is correct?
my gut instinct have said no because not want view layer know details of model objects. not strict decoupling. if pass specific values instead of passing custom data model need stick standard/primitive values (e.g. int number of wheels) , may require more coding.
have understood mvc correctly? there reason why view should not know custom classes of model layer?
if understanding question correctly, view needs know details of car object in of cases. can utilize metadata in way this:
model:
public class car { [display(name = "number of wheels")] public int wheels { get; set; } }
view: @model namespace.models.car
@* display whatever [display(name="value")] decorator defines display name, editor respect data type decorator. *@ @html.labelfor(m => m.wheels) @html.editorfor(m => m.wheels)
in case if pass down primitive metadata model lost.
Comments
Post a Comment