tags:

views:

78

answers:

1

I have an MVC application. Say for example if we have a dropdown Cars makes which when selected posts to itself and gets Car Models. Now on post, the field Car makes loses it value. I am using Form.Get("combo_box_field_name") and if it has a value I am prepopulating the car make dropdown. As lot of controls on my form do this sort of post and i have to prepopulate the fields , I was wondering if this is the right way of doing stuff. I have done loads of asp classic works and also asp.net and looks like mvc is very similar in approach tp classic asp. If someone can guide in in the right way this can be handled it would be greatly appreciated. I am not looking to use AJAX so pls dont tell me with regard to cascading dropdowns and I have a host of other controls in the form which will need updating on the form being posted to itself before I leave the page to save the data

+1  A: 

I don't think I've ever used Form.get in my MVC application.

I post back to the controller which looks like;

    [AcceptVerbs(HttpVerbs.Post), Authorize]
    public ActionResult MyAction(FormCollection collection)
    {
        MyClass myClass = new MyClass();
        UpdateModel(myClass);

        //do stuff with data

        return View(myClass);
    }

So basically you're letting MVC grab the data from the view for you.

You may need to reload your dropdown lists with this but you can get around that by using JSON to do partial postbacks.

griegs
Do you have to translate the collection to the domain object myClass?
chugh97