Click here to Skip to main content
15,039,714 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to display the data of the columns with checkboxes for each row based on the input given from the dropdownlist. I am new to mvc so not able to figure the solution. Please help me out.

Here is my Controller

C#
namespace RoomMovement.Controllers
{
    public class DefineController : Controller
    {
        private RoomMove_DEVEntities db = new RoomMove_DEVEntities();

        // GET: Define
        public ActionResult Index()
        {
            IEnumerable<SelectListItem> Rooms = db.RM_ROOM.Select(c => new SelectListItem
            {
                Value = c.NAME,
                Text = c.NAME

            });
            ViewBag.NAME = Rooms;

            IEnumerable<SelectListItem> item = db.RM_ENTITY_TYPE.Select(c => new SelectListItem
            {
                Value = c.ENTITY_NAME,
                Text = c.ENTITY_NAME

            });
            ViewBag.ENTITY_NAME = item;
            //var rooms = db.RM_ROOM.ToList();

          
            return View();
      

        }
        [HttpPost]
        public ActionResult Index(String NAME)
        {
            //  var room = from r in db.RM_ROOM.Find(r.NAME == NAME);
            //  return Content("Selected Room: " + model.NAME + model.ENTITY_NAME, "text/plain");
            //    DefineViewModelcs define = new DefineViewModelcs();
            //    var room = from s in db.RM_ROOM
            //                select s;
            //    return (room.ToList());
            //var rooms = from s in db.RM_ROOM
            //            select s;
            //rooms = rooms.Where(s => s.NAME.Contains(NAME));
            // return View(rooms);
            RM_ROOM rM_ROOM = db.RM_ROOM.Find(NAME);
            if (rM_ROOM == null)
            {
                return HttpNotFound();
            }
            return View(rM_ROOM);
          
        }


    }


and my view is

Razor
@using (Html.BeginForm("Define", "Home", FormMethod.Post))
{

    <div class="container">
        <div class="row">
            <div class="col-sm-1">
       Room
               @Html.DropDownList("NAME", " ")
            </div>
        </div>
        <div class="row">
            <div class="col-sm-2">
                Entity
                @Html.DropDownList("ENTITY_NAME", "")
            </div>
        </div>
    </div>
    <br />
    <input type="submit" value="Submit" />
           }



           @if (Model.Count() > 0) {  <table>
    <tr>
        <th>
            OrderDesc
        </th>
       
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.NAME)
            </td>
            
            </tr>
    }
    </table>

}


View model is

C#
namespace RoomMovement.Models
{
    using System;
    using System.Collections.Generic;
    using System.Web.Mvc;
    public class DefineViewModelcs
    {
        public IEnumerable<SelectListItem> Rooms { get; set; }
        public List<rm_room> rooms { get; set; }
        public List<rm_approved_room_state>approved{get;set;}
        public List<rm_entity_type> entities { get; set; }
        public int ROOMID { get; set; }
        public string NAME { get; set; }
        public IEnumerable<SelectListItem> Entities { get; set; }
        public int ENTITY_TYPEID { get; set; }
        public string ENTITY_NAME { get; set; }
        public int APPROVED_ROOM_STATEID { get; set; }
        public bool Selected { get; set; }





    }
}
Posted
Updated 6-Jul-16 5:59am
v2

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