如何在不使用EditorFor的情况下将值传递给列表?

时间:2017-03-17 01:56:08

标签: c# asp.net-mvc

我有这样的观点,我发现我必须使用@ Html.EditorFor将值传递给列表,如果我使用@ Html.DisplayFor,则值不会传递,我怎样才能将值传递给列出使用的东西而不是@Html.EditorFor

@model IList<TRecord>
@using (Html.BeginForm())
{
    // display names area

    @for (var i = 0; i < Model.Count; i++)
    {
        <tr>
            <td>
                @Html.DisplayFor(item => item[i].Tid)
            </td>
            <td>
                @Html.EditorFor(item => item[i].Tname)
            </td>
        </tr>
    }

    // submit button area
}

1 个答案:

答案 0 :(得分:1)

你的意思是它无法编辑吗?

如果是,请试试这个。

#include<iostream>
#include<list>

using namespace std;

struct node
{ 
    int no;
    node() { }
    node(int i) { no = i; }
};

int main()
{
    struct node * arrayOf4Nodes = new node[4];

    cout << "Enter four values: ";
    int i;
    for(i = 0; i < 4; i ++) {
        cin >> arrayOf4Nodes[i].no;
    }

    cout << "The values are:" << endl;
    for(i = 0; i < 4; i ++) {
        cout << arrayOf4Nodes[i].no << endl;
    }

    delete [] arrayOf4Nodes;

    // OR for unknown lengths

    cout << "Enter values ending with -1000 to exit: ";
    list<node> listOfNodes;
    while (true) {
        cin >> i;
        if (cin.eof() || i == -1000)
            break;
        listOfNodes.push_back(node(i));
    }

    cout << "The values are:" << endl;
    for (node n : listOfNodes) {
        cout << n.no << endl;
    }

    return 0;
}