Understanding relations between model view and controller -


i went through lot of readings mvc , each of these more or less clear. haven't understood yet how relate. mean, know these relationships

mvc relationships

but how implemented? happens in mvc framework?

i have few questions:

  • i read a view can't coupled controller, in other words can't have controller object inside, how use proper controller if view supposed trigger in it?

  • how can model update view if unique job represent data?

  • is business logic inside controller or model? have read conflicting points of view

the basic explination of mvc have each of 3 layers.

model

  • this contains data. i.e database or set of classes.

view

  • this displays data user i.e html page.
  • contains controls user interaction.

controller

  • all access data should go through layer. i.e load data data source(model) , save data data source.
  • carries out data manipulation before saving or loading.

this create separation of concerns theoretically allowing change in either layer without other layer knowing or caring making far more maintainable , readable code.

in practice can become more complicated depending on how wish access data , display although basic principles still apply, meaning each part of mvc pattern made of smaller parts.

in terms of implementing example asp.net mvc http://www.asp.net/mvc. following simple implementation of displaying data via mvc using c#.

model (c# class)

public class person{     public string firstname { get; set; }     public string lastname { get; set; } } 

controller

public actionresult index(){     return view(new person() { firstname = "person", lastname = "1" }); } 

view (index.cshtml)

@model person  full name: @html.raw(model.firstname + " " + model.lastname) 

this output onto web page

full name : person 1

please forgive me syntax errors, not tested.

more detailed post: http://www.tutorialspoint.com/design_pattern/mvc_pattern.htm


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -