在我比较两个字符串的项目上工作,字符串如何匹配,但由于某种原因它返回false ...
这是我尝试比较的代码:
@using (Html.BeginForm("Index", "Projects", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
{
var allProjects = ViewData["allProjects"] as List<Project>;
<h3>
<a href="#">Inhouse projekt</a>
</h3>
<div>
@{
Html.RenderPartial("Projects", allProjects.Where(x => x.ProjectStatu.Name == "Pågående - Inhouse"));
}
</div>
<h3>
<a href="#">Outhouse projekt</a>
</h3>
<div>
@{
Html.RenderPartial("Projects", allProjects.Where(x => x.ProjectStatu.Name == "Pågående - Outhouse"));
}
</div>
<h3>
<a href="#">Övriga projekt</a>
</h3>
<div>
@{
Html.RenderPartial("Projects", allProjects.Where(x => x.ProjectStatu.Name != "Pågående - Inhouse" && x.ProjectStatu.Name != "Pågående - Outhouse" && x.ProjectStatu.Name != "Avslutat"));
}
</div>
<h3>
<a href="#">Avslutade projekt</a>
</h3>
<div>
@{
Html.RenderPartial("Projects", allProjects.Where(x => x.ProjectStatu.Name == "Avslutat"));
}
</div>
<input type="submit" value="Spara" id="submit" name="submit" style="padding: 5px 20px 5px 20px; float: right;" />
}
}
答案 0 :(得分:0)
尝试使用allProjects.Where(x => x.ProjectStatu.Name.Contains("Inhouse"))
答案 1 :(得分:0)
而不是像那样进行比较,而应该使用string.Compare。这里的链接还包括文化信息,这可能与您的案例相关。
allProjects.Where(x => string.Compare(x.ProjectStatu.Name, {your string}, false, CultureInfo.InvariantCulture);
我这样说是因为我很容易看到两个字符串的Unicode格式存在问题。这应该绕过它。