SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
Sviluppo applicazioni web e linguaggio HTML

                               LEZIONE 06




ASP.NET
Model View Controller
Model
Che cos’è il Model?
Un insieme di classi che
modellano le entità del
dominio applicativo




                 Domain Model
Solo questo?
… e poi trasporta
            le informazioni
dall’interfaccia utente al
  database e viceversa
Per realizzare tutto questo
cosa dobbiamo fare?
Dobbiamo …
Dobbiamo …
1   Creare un controller
Dobbiamo …
    Creare un controller
2   Aggiungere le action per
    creare, modificare e
    cancellare
Dobbiamo …
    Creare un controller
    Aggiungere action per
    creare, modificare e
    cancellare
3   Creare le viste
Dobbiamo …
    Creare un controller
    Aggiungere action per
    creare, modificare e
    cancellare
    Creare le viste
4   Aggiungere la logica di
    persistenza sul database
In una parola …
Ma come facciamo a
ottenere informazioni
dal client?
In HTML è possibile grazie
al tag form
Il form è un
contenitore di
elementi di
tipo “input”
Tra questi il
pulsante di tipo
submit permette
di inviare i dati
al server




http://wufoo.com/gallery/templat
es/forms/vendor-contact-
information-form/
Quello che si trova all’interno
del tag form al submit viene
impacchettato e spedito al
server in una richiesta POST
Nell’action del controller
leggiamo le informazioni
dalla Request.Form
ma c’è un modo migliore
per farlo …
Se i nomi dei campi del
form riflettono i nomi delle
proprietà …
… possiamo usare lo
stesso codice per
valorizzare il model con i
dati dell’utente!
In ASP.NET c’è una classe
che lo fa per noi …
<form action=“/post/edit/”>
  <input type=“hidden” … name=“PostId” />
  <input type=“text” … name=“Title”/>
  <textarea name=“Body” ... ></textarea>
  …
</form>
…




…
Nel compilare la form
possiamo farci aiutare
dagli HtmlHelper
Html.EditorFor
Aggiungiamo al
blog la possibilità
di lasciare dei
commenti sui post
HtmlHelper perché

• Perché ci permettono di sfruttare le
  caratteristiche del model
• Facilitano la scrittura dell’HTML
• Aiutano nella validazione degli input
  degli utenti
HtmlHelper quando

• Quando il motivo principale è evitare
  di scrivere codice HTML
Cosa può succedere se
non controlliamo i dati
inseriti dall’utente?
La validazione degli input
può avvenire:
• Lato server [obbligatorio]
• Lato client [opzionale]
• Su entrambi [consigliato]
Per la validazione ASP.NET
MVC3 si avvale di:
• Data Annotations
• Validation Helpers
Data Annotations
Sono attributi che vengono
associati alle proprietà di
una classe del model
Data Annotations
Sono attributi che vengono
associati alle proprietà di
una classe del model
e descrivono quale insieme
di valori sono accettati
Data Annotations
          Se poi ci sono errori …
Validation Helpers
Visualizzano le informazioni
sugli errori di validazione
continua …
Credits
Le immagini contenute in questa presentazione
hanno licenza Creative Commons


Slide 6: http://www.flickr.com/photos/14497446@N02/5212627246/
Thank You   MANUEL SCAPOLAN
            website: www.manuelscapolan.it
            twitter: manuelscapolan
            e-mail: info@manuelscapolan.it

Más contenido relacionado

Destacado

The death penalty is an ineffective way to reduce corruption rate in Indonesia
The death penalty is an ineffective way to reduce corruption rate in IndonesiaThe death penalty is an ineffective way to reduce corruption rate in Indonesia
The death penalty is an ineffective way to reduce corruption rate in IndonesiaBobby Hamenda
 
Why Encryption For The Cloud Is A Good Idea
Why Encryption For The Cloud Is A Good IdeaWhy Encryption For The Cloud Is A Good Idea
Why Encryption For The Cloud Is A Good Ideaarbingersys
 
ECM And Enterprise Metadata in SharePoint 2010
ECM And Enterprise Metadata in SharePoint 2010ECM And Enterprise Metadata in SharePoint 2010
ECM And Enterprise Metadata in SharePoint 2010Phuong Nguyen
 
The death penalty is an ineffective way to reduce corruption rate in indonesia
The death penalty is an ineffective way to reduce corruption rate in indonesiaThe death penalty is an ineffective way to reduce corruption rate in indonesia
The death penalty is an ineffective way to reduce corruption rate in indonesiaBobby Hamenda
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
 

Destacado (6)

The death penalty is an ineffective way to reduce corruption rate in Indonesia
The death penalty is an ineffective way to reduce corruption rate in IndonesiaThe death penalty is an ineffective way to reduce corruption rate in Indonesia
The death penalty is an ineffective way to reduce corruption rate in Indonesia
 
Why Encryption For The Cloud Is A Good Idea
Why Encryption For The Cloud Is A Good IdeaWhy Encryption For The Cloud Is A Good Idea
Why Encryption For The Cloud Is A Good Idea
 
Ueki Town
Ueki TownUeki Town
Ueki Town
 
ECM And Enterprise Metadata in SharePoint 2010
ECM And Enterprise Metadata in SharePoint 2010ECM And Enterprise Metadata in SharePoint 2010
ECM And Enterprise Metadata in SharePoint 2010
 
The death penalty is an ineffective way to reduce corruption rate in indonesia
The death penalty is an ineffective way to reduce corruption rate in indonesiaThe death penalty is an ineffective way to reduce corruption rate in indonesia
The death penalty is an ineffective way to reduce corruption rate in indonesia
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similar a ASP.NET MVC 3 - Trasportare i dati nel Model

Sviluppo di App con Qt Quick: un esempio di model-view-delegate
Sviluppo di App con Qt Quick: un esempio di model-view-delegateSviluppo di App con Qt Quick: un esempio di model-view-delegate
Sviluppo di App con Qt Quick: un esempio di model-view-delegatePaolo Sereno
 
Hands on MVC - Mastering the Web
Hands on MVC - Mastering the WebHands on MVC - Mastering the Web
Hands on MVC - Mastering the WebClaudio Gandelli
 
Giovambattista Fazioli, 10 more things
Giovambattista Fazioli, 10 more thingsGiovambattista Fazioli, 10 more things
Giovambattista Fazioli, 10 more thingsKnowCamp
 
What's New in ASP.NET 4.5 and Visual Studio 2012
What's New in ASP.NET 4.5 and Visual Studio 2012What's New in ASP.NET 4.5 and Visual Studio 2012
What's New in ASP.NET 4.5 and Visual Studio 2012Andrea Dottor
 
Web Api – The HTTP Way
Web Api – The HTTP WayWeb Api – The HTTP Way
Web Api – The HTTP WayLuca Milan
 
Alessandro Forte - Realizzare controlli Ajax in ASP.Net
Alessandro Forte - Realizzare controlli Ajax in ASP.NetAlessandro Forte - Realizzare controlli Ajax in ASP.Net
Alessandro Forte - Realizzare controlli Ajax in ASP.NetAlessandro Forte
 
ASP.NET MVC3 - Tutti i compiti del Controller
ASP.NET MVC3 - Tutti i compiti del ControllerASP.NET MVC3 - Tutti i compiti del Controller
ASP.NET MVC3 - Tutti i compiti del ControllerManuel Scapolan
 
Asp.net 4 Community Tour VS2010
Asp.net 4 Community Tour VS2010Asp.net 4 Community Tour VS2010
Asp.net 4 Community Tour VS2010Fabrizio Bernabei
 
Liferay Web Services - Come importare utenti da un foglio Excel
Liferay Web Services - Come importare utenti da un foglio ExcelLiferay Web Services - Come importare utenti da un foglio Excel
Liferay Web Services - Come importare utenti da un foglio ExcelAntonio Musarra
 
Joomla! 1.5: CMS a mani tese verso gli sviluppatori
Joomla! 1.5: CMS a mani tese verso gli sviluppatoriJoomla! 1.5: CMS a mani tese verso gli sviluppatori
Joomla! 1.5: CMS a mani tese verso gli sviluppatoriGrUSP
 
Joomla! 1.5: CMS a mani tese verso gli sviluppatori
Joomla! 1.5: CMS a mani tese verso gli sviluppatoriJoomla! 1.5: CMS a mani tese verso gli sviluppatori
Joomla! 1.5: CMS a mani tese verso gli sviluppatoriAlessandro Nadalin
 
Verifica finale
Verifica finaleVerifica finale
Verifica finalegianter62
 
Meetup ASP.NET Core Angular
Meetup ASP.NET Core AngularMeetup ASP.NET Core Angular
Meetup ASP.NET Core Angulardotnetcode
 
CakePhp Linux Day Torino '09
CakePhp Linux Day Torino '09CakePhp Linux Day Torino '09
CakePhp Linux Day Torino '09Francesco Ronchi
 

Similar a ASP.NET MVC 3 - Trasportare i dati nel Model (20)

Form e HTML basi
Form e HTML basiForm e HTML basi
Form e HTML basi
 
Sviluppo di App con Qt Quick: un esempio di model-view-delegate
Sviluppo di App con Qt Quick: un esempio di model-view-delegateSviluppo di App con Qt Quick: un esempio di model-view-delegate
Sviluppo di App con Qt Quick: un esempio di model-view-delegate
 
Hands on MVC - Mastering the Web
Hands on MVC - Mastering the WebHands on MVC - Mastering the Web
Hands on MVC - Mastering the Web
 
Giovambattista Fazioli, 10 more things
Giovambattista Fazioli, 10 more thingsGiovambattista Fazioli, 10 more things
Giovambattista Fazioli, 10 more things
 
What's New in ASP.NET 4.5 and Visual Studio 2012
What's New in ASP.NET 4.5 and Visual Studio 2012What's New in ASP.NET 4.5 and Visual Studio 2012
What's New in ASP.NET 4.5 and Visual Studio 2012
 
Web Api – The HTTP Way
Web Api – The HTTP WayWeb Api – The HTTP Way
Web Api – The HTTP Way
 
Alessandro Forte - Realizzare controlli Ajax in ASP.Net
Alessandro Forte - Realizzare controlli Ajax in ASP.NetAlessandro Forte - Realizzare controlli Ajax in ASP.Net
Alessandro Forte - Realizzare controlli Ajax in ASP.Net
 
ASP.NET MVC3 - Tutti i compiti del Controller
ASP.NET MVC3 - Tutti i compiti del ControllerASP.NET MVC3 - Tutti i compiti del Controller
ASP.NET MVC3 - Tutti i compiti del Controller
 
6.01 php ajax_json_mysql
6.01 php ajax_json_mysql6.01 php ajax_json_mysql
6.01 php ajax_json_mysql
 
Asp.net 4 Community Tour VS2010
Asp.net 4 Community Tour VS2010Asp.net 4 Community Tour VS2010
Asp.net 4 Community Tour VS2010
 
Liferay Web Services - Come importare utenti da un foglio Excel
Liferay Web Services - Come importare utenti da un foglio ExcelLiferay Web Services - Come importare utenti da un foglio Excel
Liferay Web Services - Come importare utenti da un foglio Excel
 
Joomla! 1.5: CMS a mani tese verso gli sviluppatori
Joomla! 1.5: CMS a mani tese verso gli sviluppatoriJoomla! 1.5: CMS a mani tese verso gli sviluppatori
Joomla! 1.5: CMS a mani tese verso gli sviluppatori
 
Joomla! 1.5: CMS a mani tese verso gli sviluppatori
Joomla! 1.5: CMS a mani tese verso gli sviluppatoriJoomla! 1.5: CMS a mani tese verso gli sviluppatori
Joomla! 1.5: CMS a mani tese verso gli sviluppatori
 
Verifica finale
Verifica finaleVerifica finale
Verifica finale
 
Novità di Asp.Net 4.0
Novità di Asp.Net 4.0Novità di Asp.Net 4.0
Novità di Asp.Net 4.0
 
Dojo nuovo look alle vostre applicazioni web Domino
Dojo nuovo look alle vostre applicazioni web DominoDojo nuovo look alle vostre applicazioni web Domino
Dojo nuovo look alle vostre applicazioni web Domino
 
Meetup ASP.NET Core Angular
Meetup ASP.NET Core AngularMeetup ASP.NET Core Angular
Meetup ASP.NET Core Angular
 
CakePhp Linux Day Torino '09
CakePhp Linux Day Torino '09CakePhp Linux Day Torino '09
CakePhp Linux Day Torino '09
 
Many Designs Elements
Many Designs ElementsMany Designs Elements
Many Designs Elements
 
Open ideas tesina
Open ideas tesinaOpen ideas tesina
Open ideas tesina
 

Más de Manuel Scapolan

TFS and Scrum - Lessons Learned
TFS and Scrum - Lessons LearnedTFS and Scrum - Lessons Learned
TFS and Scrum - Lessons LearnedManuel Scapolan
 
Scrum? E' come fare il bucato!
Scrum? E' come fare il bucato!Scrum? E' come fare il bucato!
Scrum? E' come fare il bucato!Manuel Scapolan
 
Domain Driven Design e CQRS
Domain Driven Design e CQRSDomain Driven Design e CQRS
Domain Driven Design e CQRSManuel Scapolan
 
ASP.NET MVC 3 - Presentare i dati nella View
ASP.NET MVC 3 - Presentare i dati nella ViewASP.NET MVC 3 - Presentare i dati nella View
ASP.NET MVC 3 - Presentare i dati nella ViewManuel Scapolan
 
JavaScript Object Oriented
JavaScript Object OrientedJavaScript Object Oriented
JavaScript Object OrientedManuel Scapolan
 
Tutte le novità di ASP.NET MVC3
Tutte le novità di ASP.NET MVC3Tutte le novità di ASP.NET MVC3
Tutte le novità di ASP.NET MVC3Manuel Scapolan
 
Managed Extensibility Framework (MEF)
Managed Extensibility Framework (MEF)Managed Extensibility Framework (MEF)
Managed Extensibility Framework (MEF)Manuel Scapolan
 
Dai delegati a LINQ con C#
Dai delegati a LINQ con C#Dai delegati a LINQ con C#
Dai delegati a LINQ con C#Manuel Scapolan
 
C# e la Framework Class Library
C# e la Framework Class LibraryC# e la Framework Class Library
C# e la Framework Class LibraryManuel Scapolan
 
AntiPatterns: i vizi del programmatore
AntiPatterns: i vizi del programmatoreAntiPatterns: i vizi del programmatore
AntiPatterns: i vizi del programmatoreManuel Scapolan
 
Entity Framework 4.0 vs NHibernate
Entity Framework 4.0 vs NHibernateEntity Framework 4.0 vs NHibernate
Entity Framework 4.0 vs NHibernateManuel Scapolan
 

Más de Manuel Scapolan (17)

TFS and Scrum - Lessons Learned
TFS and Scrum - Lessons LearnedTFS and Scrum - Lessons Learned
TFS and Scrum - Lessons Learned
 
Scrum? E' come fare il bucato!
Scrum? E' come fare il bucato!Scrum? E' come fare il bucato!
Scrum? E' come fare il bucato!
 
Domain Driven Design e CQRS
Domain Driven Design e CQRSDomain Driven Design e CQRS
Domain Driven Design e CQRS
 
NOSQL
NOSQLNOSQL
NOSQL
 
Knockout.js
Knockout.jsKnockout.js
Knockout.js
 
ASP.NET MVC 3 - Presentare i dati nella View
ASP.NET MVC 3 - Presentare i dati nella ViewASP.NET MVC 3 - Presentare i dati nella View
ASP.NET MVC 3 - Presentare i dati nella View
 
JavaScript Object Oriented
JavaScript Object OrientedJavaScript Object Oriented
JavaScript Object Oriented
 
JavaScript
JavaScriptJavaScript
JavaScript
 
HTML e CSS
HTML e CSSHTML e CSS
HTML e CSS
 
Tutte le novità di ASP.NET MVC3
Tutte le novità di ASP.NET MVC3Tutte le novità di ASP.NET MVC3
Tutte le novità di ASP.NET MVC3
 
ASP.NET MVC Intro
ASP.NET MVC IntroASP.NET MVC Intro
ASP.NET MVC Intro
 
Managed Extensibility Framework (MEF)
Managed Extensibility Framework (MEF)Managed Extensibility Framework (MEF)
Managed Extensibility Framework (MEF)
 
Dai delegati a LINQ con C#
Dai delegati a LINQ con C#Dai delegati a LINQ con C#
Dai delegati a LINQ con C#
 
C# e la Framework Class Library
C# e la Framework Class LibraryC# e la Framework Class Library
C# e la Framework Class Library
 
AntiPatterns: i vizi del programmatore
AntiPatterns: i vizi del programmatoreAntiPatterns: i vizi del programmatore
AntiPatterns: i vizi del programmatore
 
OOP with C#
OOP with C#OOP with C#
OOP with C#
 
Entity Framework 4.0 vs NHibernate
Entity Framework 4.0 vs NHibernateEntity Framework 4.0 vs NHibernate
Entity Framework 4.0 vs NHibernate
 

ASP.NET MVC 3 - Trasportare i dati nel Model