This is a migrated thread and some comments may be shown as answers.

passing DropDownList selected value to controller

0 Answers 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Fred
Top achievements
Rank 1
Fred asked on 29 Dec 2011, 04:46 PM
I am looking for an example to do the following.

I have an edit template.

i call it from the grid, do some changes and if i click the save button (check icon) it saves it to the db by calling proper controler method.  this is all done without me writing any javascript (which i know nothing about for now).

However, if I change the value of the dropdownlist for a field in the edit box, that value is not changed.

I try to do some javascript code, but i was getting error message using firebug, something about dataobject not defined.

I am looking for a working example.

i figured out that the problem is that the model i am passing the view is not the same as the model as i saving in the controller (i flattened my data model to bypass the circular reference problem)

The way i pass the data to my entity object is

  Public Function _AjaxEdit(id As Integer)
            Dim ta As CUSTOMER = _db.CUSTOMERS.ToList.Find(Function(o) o.ID = id)


            ta.CITY_ID = Me.Request.Params("cityID")
            ta.ADDRESS1 = Me.Request.Params("Adress1")
            ta.Code = Me.Request.Params("Code")
            ta.Name = Me.Request.Params("Name")


            TryUpdateModel(ta)
            _db.ObjectStateManager.ChangeObjectState(ta, EntityState.Modified)
            _db.SaveChanges()

I don't think this is a good way of doing it.

Any better ideas ?




Tags
Grid
Asked by
Fred
Top achievements
Rank 1
Share this question
or