如何绑定模型列表并在ASP.NET中显示结果? [英] How Do I Bind a model list and display results in ASP.NET?

查看:58
本文介绍了如何绑定模型列表并在ASP.NET中显示结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.Net应用程序,我试图完成整理。我有一个我要提交的表格与此非常类似:



http://www.binaryintellect.net/articles/b1e0b153-47f4-4b29-8583-958aa22d9284.aspx [ ^ ]



我的唯一区别是我不想要所有的字段文本框。其中一些我只想显示为纯文本,以便用户无法编辑它们。以下是我正在使用的一些代码:



I have a .Net application that I am trying to finish putting together. I have a form that I want to submit that is very similar to this one:

http://www.binaryintellect.net/articles/b1e0b153-47f4-4b29-8583-958aa22d9284.aspx[^]

The only difference in mine is that I don't want all of my fields text boxes. Some of them I just want to display as plain text so that the user can't edit them. Here is some of the code that I am using:

@using (Html.BeginForm("save", "drnos", FormMethod.Post))
   {

       for (int i = 0; i < Model.Count; i++)
       {
           <tr>
               <td>
                   @Html.DisplayFor("drnos[" + @i + "].RVH_ID_", Model[i].RVH_ID_)
               </td>
               <td>
                   @Html.DisplayFor("drnos[" + @i + "].Last_Name", Model[i].Last_Name)
               </td>
               <td>
                   @Html.CheckBoxFor("drnos[" + @i + "].Orsos", Model[i].Orsos)

               </td>
                <td>
                   @Html.TextBox("drnos[" + @i + "].Group", Model[i].Group)
               </td>





我的问题是当我在那里有DisplayFor时,它会给出错误消息:方法的参数类型不能从用法中推断出来。尝试明确指定类型参数。



我很困惑为什么它与TextBoxes一起正常工作,但不适用于DisplayFor或CheckBoxFor。任何帮助将不胜感激!



My issue is that when I have the DisplayFor on there, it gives out the error message: The type of arguments for method cannot be inferred from the usage. Try specifying the type arguments explicitly.

I am confused on why it works fine with the TextBoxes, but not for DisplayFor or CheckBoxFor. Any help would be appreciated!

推荐答案

只需将数据直接写入页面



Just write the data direct to the page

<td>
    @Model[i].Last_Name
</td>


这篇关于如何绑定模型列表并在ASP.NET中显示结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆