CRUD in ASP.NET MVC 1 vs MVC 3 -


O People I'm at www.asp.net It has been written for ASP.NET MVC1. Although most of the stuff works for MVC3, I have a question about this code:

ASP.NET MVC 1.0 (directly from the tutorial) (

  [AcceptVerbs (HttpVerbs.Post)); {_entities.AddToContactSet ( Try contactToCreate; _entities.SaveChanges (); Return Redirect Action ("Index");} Hold {Return View ();}}   

ASP.NET MVC 3 ( Microsoft Action Project by Micro 3 project generated by Microsoft 3 Project)

  [HTTP post] Create public action roles (try {_details.edu.contacts (collection); // sync Error: Error: Check Changes (); Return Redirect Action ("Index");} Hold {Return View ();}}   

So my question is that in the first case Contact Contact Contact why pass Es, but form Collection in the other?

I can easily replace the argument in another example, just contact the contact contact. , but I'm curious about what is this

collection of archives stuff? Why did MVC 3 make it for us? If it is possible to use FormCollection instead, what will the modified example look like?

form codes are the values ​​entered by the user and contacts < / Code> is the intermediate unit you are creating.

Remember that this method is originally called directly as the result of an HTTP post by the user and its poor practice to accept user input without any validity and the fact that In real-world situations, you do not have the values ​​available in a HTTP post request in accordance with your data unit properties, perhaps due to the fact that a formCollection

The revised example will look something like this:

  [htmlpost] Public Action Result (Formal Collection) ({trace for corporate} Validate and do content contact; if ( ContactToCreate! = Void) {_entities.AddToContacts ()); _entities.SaveChanges (); Return Redirect Action ("index");}} Grip (Exception) {// To display an error on logic view here goes , E.g., Base.Data ["Exception"] = Purpose:} See Return ();} Private Contact Valid & End Contact (Form Collection Collection) {// Your Implementation Here}   

Validate and Contact Crete User should validate the input and return a suitable contact object input if all is OK, then it should return the null and display a suitable error to the user Take care of (for example New ViewData by property settings.]

Comments