Page view counter

UpdateFrom in MVC Preview 2

Last post 03-13-2008 6:04 PM by katokay. 7 replies.

Sort Posts:

  • UpdateFrom in MVC Preview 2

    03-10-2008, 8:24 PM
    • Loading...
    • AlexBecker
    • Joined on 01-29-2008, 1:29 PM
    • Buenos Aires, Argentina
    • Posts 19
    • Points 6

    What happened to UpdateFrom in Preview 2?. How come it's not an extension method anymore? :S

    Thx 

  • Re: UpdateFrom in MVC Preview 2

    03-10-2008, 10:55 PM
    Answer
    • Loading...
    • robconery
    • Joined on 02-23-2005, 10:16 PM
    • Posts 192
    • Points 846
    • AspNetTeam

     One of the things we wanted to do was move away from hanging any extensions off of Object (which is where UpdateFrom() used to live). It's now located in System.Web.Mvc.BindingHelperExtensions (which I think will get renamed) as a static method).

  • Re: UpdateFrom in MVC Preview 2

    03-11-2008, 9:39 AM
    • Loading...
    • katokay
    • Joined on 12-03-2006, 11:37 AM
    • Posts 50
    • Points 93

     Seems like it might be nice as Request.Form.DeserializeTo, Which would also allow for Request.QueryString.DeserializeTo, etc.

  • Re: UpdateFrom in MVC Preview 2

    03-11-2008, 6:08 PM
    • Loading...
    • robconery
    • Joined on 02-23-2005, 10:16 PM
    • Posts 192
    • Points 846
    • AspNetTeam

    I like it - very nice - perhaps Request.Serialize() and Request.Deserialize(). This is why Phil and Eilon love me... I feel some proto-code coming...

  • Re: UpdateFrom in MVC Preview 2

    03-12-2008, 5:17 AM
    • Loading...
    • kombatsanta
    • Joined on 03-07-2008, 3:18 PM
    • Posts 8
    • Points 6

    So how would be the "correct" way to update an object? I mean instead of doing the following:

      

    public void Create()

    {

    Product product = new Product();

    product.UpdateFrom(Request.Form);

    northwind.AddProduct(product);

    northwind.SubmitChanges();

    RedirectToAction(
    "List");

    }

    You would do it like? 

     

  • Re: UpdateFrom in MVC Preview 2

    03-12-2008, 7:02 AM
    • Loading...
    • nicosabena
    • Joined on 03-12-2008, 10:58 AM
    • Posts 6
    • Points 2

    It seems that you just need to change the line:

    product.UpdateFrom(Request.Form);

    to:

    BindingHelperExtensions.UpdateFrom(product, Request.Form);


     

  • Re: UpdateFrom in MVC Preview 2

    03-12-2008, 8:50 AM
    • Loading...
    • kombatsanta
    • Joined on 03-07-2008, 3:18 PM
    • Posts 8
    • Points 6

    Hmmm... yeah. That worked for my Create method:

    public void Create()

    {

    Product product = new Product();BindingHelperExtensions.UpdateFrom(product, Request.Form);

    northwind.AddProduct(product);

    northwind.SubmitChanges();

    RedirectToAction(
    "List");

    }

    But in my Add method I still have to do this:

    public void Update(int id, string ProductName, int CategoryID, int SupplierID, Decimal UnitPrice)

    {

    Product product = northwind.GetProductById(id);product.ProductName = ProductName;

    product.CategoryID = CategoryID;

    product.SupplierID = SupplierID;

    product.UnitPrice = UnitPrice;

    northwind.SubmitChanges();RedirectToAction("List");

     

    }

    instead of this:

    public void Update(int id)

    {

    Product product = northwind.GetProductById(id);BindingHelperExtensions.UpdateFrom(product, Request.Form);

    northwind.SubmitChanges();

    RedirectToAction(
    "List");

     

    }

  • Re: UpdateFrom in MVC Preview 2

    03-13-2008, 6:04 PM
    • Loading...
    • katokay
    • Joined on 12-03-2006, 11:37 AM
    • Posts 50
    • Points 93

     http://www.hanselman.com/blog/ImJustACavemanTheHanselmanCorollaryToTheClarkeWheelerLaws.aspx

    Yes, I agree it has a nice ring to it. Big Smile 

Page 1 of 1 (8 items)