Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the DDLlist Selected Value in MVC C# Controller
    primarykey
    data
    text
    <p><strong>My coding are as following.</strong></p> <p>I cannot get the selected value of AreaDetails_code dropdownlist selected value.</p> <p>I got the null value only. Pls help me. Thanks in advance.</p> <p><strong>In my Create.cshtml</strong></p> <pre><code>&lt;div id="hsp-planner"&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; $('#butGenerate').click(`function generateTimeLine() { $('#hsp-planner').html(''); var _location = $('#pAreaInfoId').val(); var _staff = $('#pStaff').val(); var _selVal = $('#AreaDetails_code').val(); $.ajax({ url: '@Url.Action("GetAjaxPlanner", "HourlyShiftPlanner")', data: { location: _location, staff: _staff, selectval: _selVal }, //dataType: 'json', success: function (data) { $('#hsp-planner').html(data); }, failure: function (response) { alert(response); } }); }); }); ` &lt;/script&gt; </code></pre> <p><strong>In my Controller.cs</strong></p> <pre><code>public string GetAjaxPlanner() { string locationId = Request.QueryString["location"]; string staffId = Request.QueryString["staff"]; string selectVal = Request.QueryString["selectval"]; //String str = (String)req.getParameter("AreaDetails_code"); if (locationId != null &amp;&amp; locationId != "") { List&lt;ShiftAllocation&gt; saList = new ShiftAllocationRepository().FindByAreaInfoId(int.Parse(locationId)); if (saList.Count &gt; 0) { string result = ""; result = "&lt;table&gt;"; result += "&lt;tr&gt;"; result += "&lt;td&gt;Time Period&lt;br/&gt;(From-To)&lt;/td&gt;"; result += "&lt;td&gt;Duty Location&lt;/td&gt;"; //result += "&lt;td&gt;Remark&lt;/td&gt;"; result += "&lt;td&gt;Staff&lt;/td&gt;"; result += "&lt;/tr&gt;"; int i = 1; foreach (ShiftAllocation sa in saList) { HourlyShiftPlanner objHsp = null; string dutyLocation = ""; string remark = ""; if (staffId != null &amp;&amp; staffId != "") { objHsp = new HourlyShiftPlannerRepository().FindStaff(int.Parse(staffId), int.Parse(locationId), sa.ShiftAllocationId); } if (objHsp != null) { dutyLocation = objHsp.DutyLocation; remark = objHsp.Remark; } result += "&lt;tr&gt;"; result += "&lt;td&gt;" + sa.FromShift.ToString("HH:mm") + "-" + sa.ToShift.ToString("HH:mm") + "&lt;/td&gt;"; result += "&lt;td&gt;" + this.GetLocDetailsListWithDDL(i) + "&lt;/td&gt;"; result += "&lt;/tr&gt;"; result += "&lt;input type='hidden' name='hidSAId" + i + "' id='hid-sa-id" + i + "' value='" + sa.ShiftAllocationId + "'/&gt;"; i++; } result += "&lt;/table&gt;"; return result; } } return null; } private string GetLocDetailsListWithDDL(int idx2) { List&lt;AreaInfoDetails&gt; _areaDetailsList = db.AreaInfosDetails.ToList(); if (_areaDetailsList.Count == 0) return ""; string result = ""; result = "&lt;select name='AreaDetails_code" + idx2 + "' id='AreaDetails_code" + idx2 + "'&gt;"; result += "&lt;option value=&gt;--Select item--&lt;/option&gt;"; foreach (AreaInfoDetails _ad in _areaDetailsList) { result += "&lt;option value='" + _ad.AreaInfoDetailsId + "'&gt;" + _ad.AreaDetailsCode + " &lt;/&gt;"; } result += "&lt;/select&gt;"; //result += "&lt;input type=submit id=submit value=Submit &lt;/&gt;"; return result; }` </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload