0

I have simple table with users, which have edit column, so when you click it, you can edit this specific row. One of columns in my tables is TimeZone, so you can choose in which time zone you are. So proper way to create edit filed is Dropdown list.

So I find this code and implemented it in my controller:

    public ActionResult Edit(int id = 0)
    {
        using (var dbVn = new userDbEntities())
        {
            var edit = dbVn.UsersTables.Find(id);
            if (edit == null)
            {
                return HttpNotFound();
            }
            SelectListItem item;
            var zoneList = new List<SelectListItem>();
            item = new SelectListItem();
            item.Text = "TimeZone1";
            item.Value = "1";
            zoneList.Add(item);
            item = new SelectListItem();
            item.Text = "TimeZone2";
            item.Value = "2";
            zoneList.Add(item);

            ViewBag.ZoneT = zoneList;

            return View(edit);
        }
    }

And in my view I have this:

    <div class="editor-field">
        @Html.DropDownListFor(model => model.TimeZoneId, new SelectList((IEnumerable<SelectListItem>)ViewBag.ZoneT, "Value", "Text", "1"))
        @Html.ValidationMessageFor(model => model.TimeZoneId)
    </div>

This works fine if we would have a few items (3 to 4). But if we have a list of timezonese (96), is proper to use datatable (TimeZoneTable).

Any Idea how to implement it in above code in controller...

Community
  • 1
  • 1
Daniel K Rudolf_mag
  • 287
  • 2
  • 5
  • 18
  • I have create new table in my database (userDbEntities). I name table TimeZoneTable and have two columns (ZoneID, ZoneName), and I have insert values into table, now I have to implement it in my code. – Daniel K Rudolf_mag Apr 28 '14 at 12:50
  • I think that first I will have to create connection to my table (using (var db = new userDbEntities())) than For loop where my increment i++ should be my ZoneID – Daniel K Rudolf_mag Apr 28 '14 at 13:00

0 Answers0