Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc DisplayForModel的问题_Asp.net Mvc_Asp.net Mvc 3 - Fatal编程技术网

Asp.net mvc DisplayForModel的问题

Asp.net mvc DisplayForModel的问题,asp.net-mvc,asp.net-mvc-3,Asp.net Mvc,Asp.net Mvc 3,我有以下型号: namespace Storage.Models { public class AdminDetail { public string PartitionKey { get; set; } public string RowKey { get; set; } public string Title { get; set; } public string Status { get; set; }

我有以下型号:

namespace Storage.Models
{
    public class AdminDetail
    {
        public string PartitionKey { get; set; }
        public string RowKey { get; set; }
        public string Title { get; set; }
        public string Status { get; set; }
        public string Type { get; set; }
        public string Level { get; set; }

        public string Order { get; set; }
        public int Row { get; set; }
    }
我认为有以下代码:

@model IList<AdminDetail>

<table>
    <thead>
        <tr>
            <th>@Html.LabelFor(x => x[0].Order)</th>
            <th>@Html.LabelFor(x => x[0].Order)</th>
            <th>@Html.LabelFor(x => x[0].Level)</th>
            <th>@Html.LabelFor(x => x[0].Title)</th>
            <th>@Html.LabelFor(x => x[0].Status)</th>
        </tr>
    </thead>
    <tbody>
    @foreach (var item in Model)
    {
        @Html.DisplayFor(model => item)
    }
    </tbody>
</table> 
@model-IList
@Html.LabelFor(x=>x[0]。顺序)
@Html.LabelFor(x=>x[0]。顺序)
@Html.LabelFor(x=>x[0].Level)
@Html.LabelFor(x=>x[0].Title)
@Html.LabelFor(x=>x[0]。状态)
@foreach(模型中的var项目)
{
@DisplayFor(model=>item)
}
在文件中:Views\DisplayTemplates\admindail.cshtml

    @model AdminDetail


xxxxxxxxxxxxxxxxxxxxxxxx
<tr>
    <td>@Html.DisplayFor(x => x.Order)</td>
    <td>@Html.DisplayFor(x => x.Level)</td>
    <td class="indent_@(adminDetail.Level)">@Html.DisplayFor(x => x.Title)</td>
    <td>@Html.DisplayFor(x => x.Status)</td>
    <td>@Html.ActionLink("Edit", "Edit", 
            new { pk = adminDetail.PartitionKey, rk = adminDetail.RowKey },
            new { @class = "editLink" } )</td>    
    <td>@Ajax.ActionLink("Delete", "Delete", "Menus",
            new { pk = adminDetail.PartitionKey, rk = adminDetail.RowKey },
            new AjaxOptions {
                        HttpMethod = "POST",
                        Confirm = "Are you sure you want to delete menu item ",
                        OnSuccess = "deleteConfirmation"
                    })</td>  
    <td>@Html.DisplayFor(x => x.PartitionKey) @Html.DisplayFor(x => x.RowKey)</td>
</tr>
@模型管理员详细信息
XXXXXXXXXXXXXXXXXXXXXXXXX
@DisplayFor(x=>x.Order)
@DisplayFor(x=>x.Level)
@DisplayFor(x=>x.Title)
@DisplayFor(x=>x.Status)
@ActionLink(“编辑”、“编辑”,
新的{pk=adminDetail.PartitionKey,rk=adminDetail.RowKey},
新建{@class=“editLink”})
@ActionLink(“删除”、“删除”、“菜单”,
新的{pk=adminDetail.PartitionKey,rk=adminDetail.RowKey},
新选择{
HttpMethod=“POST”,
确认=“是否确实要删除菜单项”,
OnSuccess=“删除确认”
})  
@Html.DisplayFor(x=>x.PartitionKey)@Html.DisplayFor(x=>x.RowKey)
当我的视图出现时,我看到AdminDetails记录的数据,但是没有
的格式,我也没有看到任何x。我正在使用区域,视图的代码位于区域内。我的代码是否可能因为使用区域而无法获取DisplayTemplate

以下是数据显示方式的示例:

<table>
    <thead>
        <tr>
            <th><label for="">Order</label></th>
            <th><label for="">Order</label></th>

            <th><label for="">Level</label></th>
            <th><label for="">Title</label></th>
            <th><label for="">Status</label></th>
        </tr>
    </thead>
    <tbody>
<div class="display-label">PartitionKey</div>
<div class="display-field">01</div>
<div class="display-label">RowKey</div>
<div class="display-field">02</div>
<div class="display-label">Title</div>
<div class="display-field">Test55</div>
<div class="display-label">Status</div>
<div class="display-field">New</div>
<div class="display-label">Type</div>
<div class="display-field"></div>
<div class="display-label">Level</div>
<div class="display-field"></div>

命令
命令
水平仪
标题
地位
分区键
01
罗基
02
标题
测试55
地位
新的
类型
水平仪

显示模板的路径错误。而不是:

Views\DisplayTemplates\AdminDetail.cshtml
你应使用:

Views\Shared\DisplayTemplates\AdminDetail.cshtml
注意
Shared
位。也可以是:

Views\XXX\DisplayTemplates\AdminDetail.cshtml
其中,
XXX
是当前控制器的名称,如果您希望此显示模板仅可用于此控制器

也要替换您的循环:

@foreach (var item in Model)
{
    @Html.DisplayFor(model => item)
}
与其等价物:

@Html.DisplayForModel()

你不需要循环。由于您的模型是一个集合,ASP.NET MVC将自动为此集合的每个元素调用您的显示模板。

对不起。我提出了一个又一个问题,但没有出现。刚刚编辑并把它们作为代码。数据出现了,但似乎没有格式化,也没有查看我的模板。哦,我错过了共享的、已删除的我的模板。“其中XXX是当前控制器的名称”,就是它。谢谢