【发布时间】:2013-12-06 06:46:33
【问题描述】:
我的编码如下。
我无法获取 AreaDetails_code 下拉列表选择值的选择值。
我只得到了空值。请帮助我。提前致谢。
在我的 Create.cshtml 中
<div id="hsp-planner"></div>
<script type="text/javascript">
$('#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);
}
});
});
});
`
</script>
在我的 Controller.cs 中
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 && locationId != "")
{
List<ShiftAllocation> saList = new ShiftAllocationRepository().FindByAreaInfoId(int.Parse(locationId));
if (saList.Count > 0)
{
string result = "";
result = "<table>";
result += "<tr>";
result += "<td>Time Period<br/>(From-To)</td>";
result += "<td>Duty Location</td>";
//result += "<td>Remark</td>";
result += "<td>Staff</td>";
result += "</tr>";
int i = 1;
foreach (ShiftAllocation sa in saList)
{
HourlyShiftPlanner objHsp = null;
string dutyLocation = "";
string remark = "";
if (staffId != null && staffId != "")
{
objHsp = new HourlyShiftPlannerRepository().FindStaff(int.Parse(staffId), int.Parse(locationId), sa.ShiftAllocationId);
}
if (objHsp != null)
{
dutyLocation = objHsp.DutyLocation;
remark = objHsp.Remark;
}
result += "<tr>";
result += "<td>" + sa.FromShift.ToString("HH:mm") + "-" + sa.ToShift.ToString("HH:mm") + "</td>";
result += "<td>" + this.GetLocDetailsListWithDDL(i) + "</td>";
result += "</tr>";
result += "<input type='hidden' name='hidSAId" + i + "' id='hid-sa-id" + i + "' value='" + sa.ShiftAllocationId + "'/>";
i++;
}
result += "</table>";
return result;
}
}
return null;
}
private string GetLocDetailsListWithDDL(int idx2)
{
List<AreaInfoDetails> _areaDetailsList = db.AreaInfosDetails.ToList();
if (_areaDetailsList.Count == 0) return "";
string result = "";
result = "<select name='AreaDetails_code" + idx2 + "' id='AreaDetails_code" + idx2 + "'>";
result += "<option value=>--Select item--</option>";
foreach (AreaInfoDetails _ad in _areaDetailsList)
{
result += "<option value='" + _ad.AreaInfoDetailsId + "'>" + _ad.AreaDetailsCode + " </>";
}
result += "</select>";
//result += "<input type=submit id=submit value=Submit </>";
return result;
}`
【问题讨论】:
-
使用stringbuilder类通过TagBuilder生成html标签
-
怎么做?请为我写信。谢谢
-
试一试:结果 += "
-
result += "
-
那么,这行的问题是:
var _selVal = $('#AreaDetails_code').val();,你得到 _selVal 总是空的吗?请确认
标签: c# asp.net-mvc drop-down-menu ddl selected