我想通过任何现有的字符(/,;)拆分IEnumerable列表的每个项目,我不知道如何处理这个问题。此功能的目的是获取所有现有的图,通过额外的字符分割它们,仅在屏幕上显示唯一的绘图编号并按适当的方式打勾。目前我的功能只显示正确的图表列表,我不知道是否将它们拆分(',')。这是我的函数:使用MVC4拆分IEnumerable列表的每个元素
public ActionResult CopyPlotsCSR(int id)
{
var CSR = db.CSRs.Find(id);
Quote oldQuote = CSR.OrderOld.Quote;
var qp = db.QuoteProducts.Where(q => q.QuoteID == oldQuote.ID && q.Revision == oldQuote.Revision && q.Plot != null).OrderBy(q => q.Plot);
var plots = qp.Select(j => j.Plot).Distinct();
List<PlotSelector> Plots = new List<PlotSelector>();
foreach (var item in plots)
{
Plots.Add(new PlotSelector() { Plot = item });
}
ViewBag.CSRID = id;
return View(Plots.ToList());
}
这是我的模型:
public class PlotSelector
{
public PlotSelector() { this.Select = false; }
public PlotSelector(QuoteProduct qp)
{
this.QuoteProduct = qp;
this.QuoteProductID = qp.ID;
this.Plot = qp.Plot;
this.Select = false;
}
public virtual QuoteProduct QuoteProduct { get; set; }
public long QuoteProductID { get; set; }
public string Plot { get; set; }
public bool Select { get; set; }
}
}
这是我的看法:
@model IEnumerable<ERP.ViewModels.PlotSelector>
@{
ViewBag.Title = "Quote";
ViewBag.SubTitle = "Create";
}
<h2>Create New Quote based on Plots</h2>
@Html.ActionImage("Edit", "CSR", new { id = ViewBag.CSRID }, "~/Content/Images/BackToCSR.png", "Back To CSR")
<table>
<tr>
<th>
Confirm
</th>
<th>
Plot
</th>
</tr>
@Html.EditorForModel()
</table>
这是我EditorForModel()视图:
@model ERP.ViewModels.PlotSelector
<tr>
<td>
@Html.EditorFor(i => i.Select)
@Html.HiddenFor(i => i.QuoteProductID)
</td>
<td>
@Html.DisplayFor(i => i.Plot)
</td>
</tr>
这是我的电流输出:
[CheckBox] 586, 587, 588, 589
[CheckBox] 21, 22, 25
[CheckBox] 3, 65, 68
[CheckBox] 21, 68, 586
我需要像下面的输出:
[CheckBox] 3
[CheckBox] 21
[CheckBox] 22
[CheckBox] 25
[CheckBox] 65
[CheckBox] 68
[CheckBox] 586
[CheckBox] 587
[CheckBox] 588
[CheckBox] 589
任何帮助/提示将不胜感激。谢谢。
感谢您的答复。我试过了,但是我的输出只显示了Plot列的空白空间。我现在有更多的行,但我没有看到每行上的任何值。 – Eduard 2014-11-24 12:14:58
你在'Plot'属性中有逗号分隔的地块?也看到编辑我错误地把双引号'Split()'而不是单一的 – 2014-11-24 12:17:08
我注意到了(“,”)。关于剧情属性,你是指剧情如何保存?在这种情况下,一个例子是:2,3,7,14,24,46,47,49,64,65。我的其他代码已经启动。不知道该怎么办。 – Eduard 2014-11-24 12:22:26