基于第一个ID
,它有四个记录数据,根据第二个ID,它有三个记录。
目前在视图中它显示所有七个记录在单独的行中但我需要显示两行但第一行应该在一行中包含四个绳索。
[HttpPost]
[MyExceptionHandler]
public ActionResult ViewModules(int id)
{
Domain_Bind();
dynamic mymodel = new ExpandoObject();
userType type = new userType();
List<ViewRoleModules> EmpList = type.GetRoleModulesViews(id);
string sRptModuleIDs = string.Empty;
foreach (ViewRoleModules emp in EmpList)
{
sRptModuleIDs += emp.ModuleID + ",";
}
if (sRptModuleIDs != "")
{
sRptModuleIDs = sRptModuleIDs.Remove(sRptModuleIDs.Length - 1, 1);
}
List<ViewRoleModules> RoleList;
List<ViewRoleModules> test = new List<ViewRoleModules>();
foreach (var rid in sRptModuleIDs.Split(','))
{
string RID = rid;
RoleList = type.GetSiteRoleModulesViews(rid);
foreach (ViewRoleModules vip in RoleList)
{
test.Add(new ViewRoleModules {
RoleName = vip.RoleName
});
}
}
return Json(test, JsonRequestBehavior.AllowGet);
}
在List<ViewRoleModules> test = new List<ViewRoleModules>();
列表中我们存储了7条记录,但我需要基于ID
的单独数据
public List<ViewRoleModules> GetSiteRoleModulesViews(string rid)
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Admin"].ConnectionString))
{
List<ViewRoleModules> RoleList = new List<ViewRoleModules>();
SqlCommand com = new SqlCommand("MEDEIL_SiteRoleModules_SelectOne", conn);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@ModuleID", Convert.ToInt32(rid));
SqlDataAdapter da = new SqlDataAdapter(com);
DataTable dt = new DataTable();
conn.Open();
da.Fill(dt);
conn.Close();
foreach (DataRow dr in dt.Rows)
{
RoleList.Add(
new ViewRoleModules
{
RoleID = Convert.ToInt32(dr["RoleID"]),
RoleName = Convert.ToString(dr["RoleName"])
}
);
}
return RoleList;
}
}
在上面的图片中,它显示所有记录单独的行,但我需要显示两行,但第一行应在一行中包含四根绳索。
<script>
$(document).ready(function () {
$("#DomainID").change(function () {
var id = $(this).val();
$("#example tbody tr").remove();
$.ajax({
type: 'POST',
url: '@Url.Action("ViewModules")',
dataType: 'json',
data: { id: id },
success: function (data) {
var items = '';
$.each(data, function (i, item) {
$("#findValue").show();
var rows = "<tr>"
+ "<td>" + i + "</td>"
+ "<td>" + item.ModuleName + "</td>"
+ "<td>" + item.Url + "</td>"
+ "<td>" + item.RoleName + "</td>"
+ "</tr>";
$('#example tbody').append(rows);
});
},
error: function (ex) {
var r = jQuery.parseJSON(response.responseText);
alert("Message: " + r.Message);
alert("StackTrace: " + r.StackTrace);
alert("ExceptionType: " + r.ExceptionType);
}
});
return false;
})
});
</script>
例如,基于潜在客户ID的上方图像,它显示多个角色名称单行