小编sus*_*ite的帖子

Linq扩展方法,如何在集合中查找子递归

我已经熟悉了Linq但对扩展方法了解甚少,我希望有人可以帮助我.

所以我有这个分层集合伪代码,即:

class Product
  prop name
  prop type
  prop id
  prop List<Product> children
Run Code Online (Sandbox Code Playgroud)

我有一个产品列表产品列表.

有没有什么办法可以通过id用扩展方法在这个集合中查找产品?换句话说,我需要在层次结构中的某个位置使用一个项目.

c# linq recursion extension-methods hierarchy

11
推荐指数
2
解决办法
1万
查看次数

剃刀:在循环中添加变量而不显示它

嗨我想知道如何在foreach循环expamle中添加数字而不显示它们:

@{ int intVariable = 0; }

@foreach(var item in @Model.Collection)
{
    @(intVariable += item.MyNumberOfInteres) //->how can I calculate this without it being rendered to the website ?

    //some Html code.......
}
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?

欢呼
sushiBite

c# foreach loops razor asp.net-mvc-3

9
推荐指数
2
解决办法
1万
查看次数

用剃须刀提交父母和孩子

嗨,我想提交父母和孩子,我能够提交父母罚款,但不是孩子,有没有办法做到这一点?

这是我的代码.

@model IECWeb.Models.CurrencyDay

using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
    <legend>CurrencyDay</legend>

    <div class="editor-label">
        @Html.LabelFor(model => model.CurrencyDate)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.CurrencyDate)
        @Html.ValidationMessageFor(model => model.CurrencyDate)
    </div>

    <p />

    <table>
        <tr>
            <th>Currency</th>
            <th>Rate</th>
        </tr>
        @foreach (var item in Model.Currency) {
            <tr>
                <td>
                    <div class="editor-field">
                        @Html.EditorFor(model => item.Name)
                        @Html.ValidationMessageFor(model => item.Name)
                    </div>
                </td>
                <td>
                    <div class="editor-field">
                        @Html.EditorFor(model => item.Rate)
                        @Html.ValidationMessageFor(model => item.Rate)
                    </div>
                </td>
            </tr>
        }
    </table>

    <p>
        <input type="submit" value="Create" />
    </p>
</fieldset>
Run Code Online (Sandbox Code Playgroud)

当我提交时,我得到CurrencyDay对象但不是货币列表

谢谢sushiBite.

submit parent-child razor asp.net-mvc-3

2
推荐指数
1
解决办法
2950
查看次数