Click here to Skip to main content
15,879,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my view:
C#
<div class="editor-label">
            @Html.DisplayName("Length") |
              
        </div>
        <div class="editor-field">
            @Html.DropDownList("Size_ID",ViewBag.Size_ID as SelectList)
            @Html.ValidationMessageFor(model => model.Size_ID)  
            
        </div>
        <div class="editor-label">
            @Html.DisplayName("Width") 
        </div>

        <div class="editor-field">
            @Html.DropDownList("Size_ID",ViewBag.Size_ID2 as SelectList)

        </div>

this is my controller:
SQL
// GET: /Carpet/Create

      public ActionResult Create()
      {
          ViewBag.Size_ID = new SelectList(db.Sizes, "Size_ID", "Length");
          ViewBag.Size_ID2 = new SelectList(db.Sizes, "Size_ID", "width");
          return View();
      }

      //
      // POST: /Carpet/Create

      [HttpPost]
      public ActionResult Create(Carpet carpet)
      {
          if (ModelState.IsValid)
          {
              db.Carpets.Add(carpet);
              db.SaveChanges();
              return RedirectToAction("Index");
          }

          ViewBag.Size_ID = new SelectList(db.Sizes, "Size_ID", "Length", carpet.Size_ID);
          ViewBag.Size_ID2 = new SelectList(db.Sizes, "Size_ID", "width", carpet.Size_ID);
          return View(carpet);
      }

and for width by length method is:
SQL
public ActionResult Create()
      {
          //var sizeList=from s in db.Sizes
          ViewBag.Size_ID = new SelectList(db.Sizes,  "Size_ID", string.Format("{0}X{1}", "Length", "width"));
          //ViewBag.abc = ViewBag.Size_ID;
          return View();
      }
Posted
Updated 23-Feb-15 2:53am
v6
Comments
ZurdoDev 23-Feb-15 9:16am    
What's the problem?

1 solution

In db.Carpets model.. you need to have one more property with name MesurementSize.. which will concate length + 'x' + width.. and that you can show in dropdown... instead of only hight or width... you can do concatenation after retrieving data from database...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900