views:

37

answers:

1

Hi

I'm using the NerdDinner MVC1 code. Created a viewmodel called DinnerFormViewModel:

public class DinnerFormViewModel
    {
        public Dinner Dinner { get; private set; }
        public SelectList Countries { get; private set; }

        public DinnerFormViewModel(Dinner dinner)
        {
            Dinner = dinner;
            Countries = new SelectList(PhoneValidator.Countries, dinner.Country);
        }
    }

I pass to my edit view fine which uses strongly typed helpers in MVC2. Passing back however:

 public ActionResult Edit(int id, FormCollection collection)
        {
            Dinner dinnerToUpdate = dr.GetDinner(id);
            try
            {
                UpdateModel(dinnerToUpdate, "Dinner"); // using a helper becuase of strongly typed helpers to tell it what to update
                                                // updates the properites of the dinnerToUpdate object using incoming form parameters collection.
                                                // UpdateModel automatically populates ModelState when it encounters errors
                                                // works by when trying to assign BOGUS to a datetime
              //  dinnerToUpdate.Country = Request.Form["Countries"];
                dr.Save(); // dinner validation may fail here too due to hook into LINQ to SQL via Dinner.OnValidate() partial method.

                return RedirectToAction("Details", new { id = dinnerToUpdate.DinnerID });
            }

This works, however my Country doesn't get updated, becuase I'm only giving the hint to UpdateModel to update the Dinner.

Question: How to get the country saving?

Thanks.

A: 

I recommend you to look into the asp.net-mvc sample application at http://valueinjecter.codeplex.com/ where some good techniques are showed

Omu
Many thanks..valueinjecter looks interesting! Am trying to keep things really simple and understand whats happening.
Dave
And you wrote the valueinjector framework.. good job!
Dave
@Dave thnx :), you can learn from the asp.net-mvc sample how to read and fill the views with data in clean way
Omu
I'll come back to this question.. am on another project currently!
Dave