2

Controller

public ActionResult Isearch( string OFFICE_TYPE,string DEPARTMENT, string FILECATEGORY,string fromdate,string todate)
            {

                ViewBag.officetype = new SelectList(entity.TBL_OFFICETYPE.ToList(), "OFID", "OFFICE_TYPE");
                //var list = new SelectList(entity.TBL_OFFICETYPE.Select(r => r.OFFICE_TYPE).ToList());

                var list2 = new SelectList(entity.TBL_DEPARTMENT.Select(r => r.DEPARTMENTCODE).ToList());
                ViewBag.department = list2;
                var list4 = new SelectList(entity.TBL_FILECATEGORY.ToList(), "FILECATEGORY", "FILECATEGORY");
                ViewBag.filecategory = list4;


                var myinboxdata = entity.TBL_INBOX.ToList();
                //var myinboxs = from res in entity.TBL_INBOX
                //               select new { res.OFFICETYPE, res.DEPARTMENTCODE, res.DESCRIPTION };
                var myinbox1=from s in entity.TBL_INBOX select s;
                if (String.IsNullOrEmpty(fromdate)&& String.IsNullOrEmpty(todate))
                {
                    //DateTime fdate = Convert.ToDateTime(fromdate).Date;
                    //DateTime tdate = Convert.ToDateTime(todate).Date;
                    myinbox1 = entity.TBL_INBOX.Where(s => s.OFFICETYPE.Contains(OFFICE_TYPE) && s.DEPARTMENTCODE.Contains(DEPARTMENT) && s.FILECATEGORY.Contains(FILECATEGORY));

                }
                else
                {

                    myinbox1 = entity.TBL_INBOX.Where(s => s.OFFICETYPE.Contains(OFFICE_TYPE) && s.DEPARTMENTCODE.Contains(DEPARTMENT) && s.FILECATEGORY.Contains(FILECATEGORY) && (s.UDATE >= Convert.ToDateTime(fromdate).Date && s.UDATE <= Convert.ToDateTime(todate)));

                }
                var data = myinbox1.OrderBy(x => x.OFFICETYPE).GroupBy(x => new { x.OFFICETYPE, x.DEPARTMENTCODE, x.DESCRIPTION }).Select(g => new { g.Key.OFFICETYPE, g.Key.DEPARTMENTCODE, g.Key.DESCRIPTION, Unread = g.Count() });
                List<Inbox> mydata = new List<Models.Inbox>();
                foreach (var myinbox in data)
                {
                    mydata.Add(new Models.Inbox { OType = myinbox.OFFICETYPE, DCode = myinbox.DEPARTMENTCODE, Desc = myinbox.DESCRIPTION, Unread = myinbox.Unread });
                }
                ViewBag.data = mydata.ToList();
                return View("Inbox");
            }`enter code here`

In thee above code i passing the data from view. While passing the data i am getting the key for office type and department. Instead i want to get their value(text)

View

@using (Html.BeginForm("Isearch", "Transactions", FormMethod.Post))
    {
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">My InBox</h3>
            </div>
            <div class="panel-body">
                <div class="col-md-12 col-sm-12">
                    <div class="form-group col-md-4 col-sm-4">
                        <label for="Office">OfficeType</label>
                        @*@Html.DropDownList("officetype", ViewBag.officetype as SelectList, new { @class = "form-control input-sm", @id = "name" })*@
                        @Html.DropDownList("OFFICE_TYPE", ViewBag.officetype as SelectList, new { @class = "form-control input-sm", @id = "Office",name="Office" })

                    </div>
                    <div class="form-group col-md-4 col-sm-4" id="depart">
                        <label for="DEPARTMENT">Department</label>
                        @*@Html.DropDownList( ViewBag.Department,Enumerable.Empty<SelectListItem>(), new { @class = "form-control input-sm"})*@,
                        <select id="DEPARTMENT" name="DEPARTMENT" class = "form-control input-sm" ></select>
</div>
                    <div class="form-group col-md-4 col-sm-4">
                        <label for="FILECATEGORY">FILECATEGORY  </label>
                        @Html.DropDownList("FILECATEGORY", ViewBag.filecategory as SelectList, new { @class = "form-control input-sm", @id = "name" })
                    </div>
                    <div class="form-group col-md-4 col-sm-4">
                        <label>From Date</label>
                        @Html.TextBox("fromdate", null, new { @id = "fromdate", @class = "form-control input-sm" })
                        @*<input name="fdate" type="text" id="fromdate" class="form-control input-sm" />*@
                    </div>
                    <div class="form-group col-md-4 col-sm-4">
                        <label>To Date</label>
                        @Html.TextBox("todate", null, new { @id = "todate", @class = "form-control input-sm" })
                        @*<input type="text" id="todate" class="form-control input-sm" />*@
                    </div>
                    <div class="form-group col-md-4 col-sm-4">
                        <br />
                        <input type="submit" value="Search" class="btn btn-primary" />
                    </div>
                </div>
            </div>
        </div>
    }

the above code is view code where i an passing the value through the id and name property. In thee above code i passing the data from view. While passing the data i am getting the key for office type and department. Instead i want to get their value(text)

1
  • to help you better ..you need to share the view code /JS code ,calling your controller to see how you are passing parameters Commented May 3, 2018 at 18:27

2 Answers 2

1

Giving you an example:

<select id="drpgenderid" name="drpgendername">


<option value="1">@Html.Label("FEMALE",Model.gender, new { @style = "", @id = "new_id_gender", @name = "name_new_gender", @placeholder = "Gender", @enabled = "false", @value = "FEMALE" })</option>

<option selected="selected" value="2">@Html.Label("MALE",Model.gender, new { @style = "", @id = "new_id_gender", @name = "name_new_gender", @placeholder = "Gender", @enabled = "false", @value = "MALE" })</option>

</select>

SCRIPT

 function GetData()
        {

            var pdrp = document.getElementById("drpgenderid");
            gender = pdrp.options[pdrp.selectedIndex].value;

        }

using AJAX

       GetData();
        $.ajax({
            type: "post",
            contentType: "application/json; charset=utf-8",

            url: "@Url.Action("GetDemoData")",

            data: "{'gender':'" + gender.trim() + "'}",
            success: function (data) {

            }
        });

CONTROLLER

  [ScriptMethod(ResponseFormat = ResponseFormat.Json)]       
   public void GetDemoData(String gender)
    {

        string gtGender = gender;

    }
Sign up to request clarification or add additional context in comments.

Comments

0

use ViewBag and @Html.DropDownList we can do drop-down without using model data

In controller

public ActionResult dropdown() {

    var customers = new List<Customer>();
    customers.Add(new Customer { Name = "Airi Satou", ID = 1 });
    customers.Add(new Customer { Name = "Brenden Wagner", ID = 2 });
    customers.Add(new Customer { Name = "Brielle Williamson", ID = 2 });
    ViewBag.DropData = customers;

    return View();
}

In View

 @Html.DropDownList("CustomerDropDown", new SelectList(ViewBag.DropData, "ID", "Name"), new { @class="form-control"})

 @Html.DropDownList("CustomerDropDown2", new SelectList(ViewBag.DropData, "Name", "Name"), new { @class="form-control"})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.