我有一个员工列表,所有员工都有另一个嵌套列表,称为DisplayList.
现在并非所有员工都拥有相同数量的DisplayField.所以我希望得到具有最高DisplayFields的那些,以便我可以将每个人都包含在显示器中.
目前我有以下内容: -
int iMaxDisplayCount = 0;
foreach (Employee employee in employeeList)
{
int iDisplayCount = employee.EmployeeDisplayCollection.Count;
if (iDisplayCount > iMaxDisplayCount)
iMaxDisplayCount = iDisplayCount;
}
var employees = employeeList.GroupBy(p => p.EmployeeDisplayCollection.Count == iMaxDisplayCount).Select(g => g.ToList());
foreach(var employeeHighList in employees)
{
foreach (var employee in employeeHighList)
{
}
}
Run Code Online (Sandbox Code Playgroud)
但是出于某种原因,我得到了employeeHighList中的所有员工,而不仅仅是拥有最高显示数量的员工.
我认为GroupBy不正确,但不知道它有什么问题.
任何帮助将非常感谢!
谢谢
我<asp:Label> 希望根据我传递给它的Generic对象进行填充.
目前我有以下代码: -
private void PopulateEnglishQuestion(int questionId)
{
ReportQuestion reportQuestion = questionsBll.GetReportQuestions().Where(x=> x.ReportQuestionId == questionId).FirstOrDefault();
PopulateLabels(reportQuestion);
}
private void PopulateTranslatedQuesiton(int questionId)
{
ReportQuestionTranslation reportQuestionTranslation = questionsBll.GetReportQuestionsTranslation().Where(x => x.QuestionId == questionId).FirstOrDefault();
PopulateLabels(reportQuestionTranslation);
}
private void PopulateLabels<T>(T item)
{
lblQuestionTitle.Text = typeof (T) == typeof (ReportQuestion)
? ((ReportQuestion) (item)).ReportQuestionTitle
: ((ReportQuestionTranslation) (item)).ReportQuestionTitleTrans;
}
Run Code Online (Sandbox Code Playgroud)
如何让PopulateLabels方法正常工作?
我有2个重载方法,因为参数SecondVar有时可用,有时不可用: -
private void DoSomething(int FirstVar)
{
int SecondVar = 0;
DoSomething(FirstVar, SecondVar);
}
private void DoSomething(int FirstVar, int SecondVar)
{
DoSomething(FirstVar, SecondVar);
if(SecondVar > 0)
{
var a = GetList().Where(x=>x.FirstId == FirstVar && x.SecondId == SecondVar);
}
else
{
var a = GetList().Where(x=>x.FirstId == FirstVar);
}
}
Run Code Online (Sandbox Code Playgroud)
是否有可能在第二个重载的DoSomething中摆脱If子句?
谢谢你的帮助和时间
我有以下WebMethod: -
[WebMethod(EnableSession = true)]
public static void OpenReport(string reportName)
{
Report report = reportsBll.GetReports().FirstOrDefault(x => reportQuestion != null && x.Id == reportQuestion.ReportId);
if (report != null) reportUrl = report.Url;
}
Run Code Online (Sandbox Code Playgroud)
现在我希望传递report.Url到这个Jquery方法: -
$('.ReportButton').click(function () {
var args = { reportName : '' };
$.ajax({
type: "POST",
url: "ReportsByQuestionsDetails.aspx/OpenReport",
data: JSON.stringify(args),
contentType: "application/json;charset=utf-8;",
success: function (data) {
alert('success');
document.location.href = reportUrl;
},
error: function () {
}
});
});
Run Code Online (Sandbox Code Playgroud)
如何将reportUrl从WebMethod传递给Jquery?
谢谢你的帮助和时间
我有以下cshtml表单
@using (Html.BeginForm(Html.BeginForm("Create", "UserRole", Model, FormMethod.Post)))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Role</legend>
<div class="editor-label">
@Html.Label(Model.User.UserName)
</div>
<div class="editor-field">
@Html.CheckBoxList(Model.CheckboxList)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
Run Code Online (Sandbox Code Playgroud)
我希望在我的操作中获取Model.CheckboxList选择的项目.
我的控制器中有以下创建操作
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(UserRoleViewModel userRoleViewModel)
{
if (ModelState.IsValid)
{
//_context.Role.Add(role);
//_context.SaveChanges();
//return RedirectToAction("Index");
}
return View(viewModel);
}
Run Code Online (Sandbox Code Playgroud)
但是viewModel.CheckboxList为0.
如何将复选框列表的选定值以及Model.User传递给Controller Action?
我的ViewModel看起来像这样: -
public User User { get; set; }
public IEnumerable<Role> RoleList { get; set; }
public List<UserRoleViewModel> UserList { get; set; }
public IEnumerable<SelectListItem> CheckboxList { get; set; } …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用JSON在部分视图中显示Google地图.我已经在普通视图中尝试了代码,它工作得很好.
我有以下内容: -
部分视图ShowMap.cshtml
@using Microsoft.Web.Helpers
<script src="~/Scripts/jquery-1.8.3.min.js"></script>
<div class="experienceRestrictedText">
@Maps.GetGoogleHtml("1, Redmond Way, Redmond, WA", width: "400", height: "400")
</div>
Run Code Online (Sandbox Code Playgroud)
Index.cshtml(启动部分视图的位置)
$('.modal_link_map').on('click', function (e) {
$('.modal_part').show();
var id = $(this).attr('data-id');
var context = $('#tn_select').load('/Experience/ShowMap?id=' + id, function () {
initSelect(context);
});
e.preventDefault();
return false;
});
Run Code Online (Sandbox Code Playgroud)
控制器动作如下: -
public ActionResult ShowMap()
{
_ItemID = Convert.ToInt32(Request.QueryString["id"]);
viewModel.ExperienceViewModel.Experience = unitOfWork.ExperienceRepository.GetByID(_ItemID);
return PartialView(viewModel);
}
Run Code Online (Sandbox Code Playgroud)
我需要包含其他任何内容才能使用此地图吗?
我有以下jquery对象: -
(function ($) {
var menu = [{
title: Main1",
href: "/"
}, {
title: "Main2",
href: "/main2",
items: [{
title: "SubMain2_1",
href: "/subMain2_1"
}, {
title: "SubMain2_2",
href: "/subMain2_2"
}]
}, {
title: "Main3",
href: "/main3",
items: [{
title: "SubMain3_1",
href: "/subMain3_1"
}, {
title: "SubMain3_2",
href: "/subMain3_2",
items: [{
title: "SubSubMain3_1",
href: "/SubSubMain3_2"
}, {
title: "SubSubMain3_2",
href: "/subSubMain3_2"
}]
}, {
title: "SubMain3_3",
href: "/subMain3_3"
}]
}, {
title: "Main4",
href: "/main4"
}];
});
Run Code Online (Sandbox Code Playgroud)
我希望把它变成
<ul> …Run Code Online (Sandbox Code Playgroud) c# ×6
asp.net ×3
asp.net-mvc ×2
jquery ×2
linq ×2
razor ×2
c#-4.0 ×1
generic-list ×1
generics ×1
javascript ×1
json ×1
selecteditem ×1