1

我的问题就在眼前……请给我一个适合我的数据库和操作的新视图。

我的详细信息表:

明细表

使用 html 操作链接传递请求 ID:

 @Html.ActionLink(item.Request_ID, "Details",new { requestid = item.Request_ID },null )

单击链接,我们应该从数据库中获取与链接对应的详细信息。

动作方法:

public ActionResult Details(string requestid)
    {
        var entities = new EmployDBEntities1();
       var detailsModel = entities.Details.Single(e => e.Id == requestid);
       return View(detailsModel);
        //return View(entities.Details.ToList());
    }

希望我的问题是返回视图和设计视图。我的要求是我想要特定 id 的详细信息,并且应该在下面设计的视图中显示它们。我能够检查 var 详细信息模型中的 id,然后我必须从数据库中读取剩余的字段并在我的视图中显示这些字段。我值得注意的是这样做。请帮我。

看法:

model IEnumerable<Approvals.Models.Detail>

@{
ViewBag.Title = "Details";
//Layout = "~/Views/Shared/_Layout.cshtml";
}

@section Header {
@Html.ActionLink("Back", "PendingRequests", "Account", null, new { data_icon = "arrow-l", data_rel = "back" })
<h1>@ViewBag.Title</h1>
@Html.ActionLink("Log Off", "LogOff") 


}

<head>
 <link href="~/StyleSheet1.css" rel="stylesheet" type="text/css" />
    </head>
<div data-role="collapsible"  data-theme="b" data-content-theme="b">
    <h3>Employee Details</h3>
    <table class="td3">
        @foreach (var item in Model) {
        <tr>
            <td>Employee ID</td>
            <td>@Html.Encode(item.EmpID)</td>
        </tr>
            <tr>
                <td>Short ID</td>
                <td>
                    @Html.Encode(item.ShortID)
                </td>
            </tr>
            <tr>
            <td>Grade</td>
            <td>@Html.Encode(item.Grade)</td>
        </tr>
            <tr>
            <td>Vertical</td>
            <td>@Html.Encode(item.Vertical)</td>
        </tr>
            <tr>
            <td>Vertical Head</td>
            <td>@Html.Encode(item.VerticalHead)</td>
        </tr>
            <tr>
            <td>L1 Manager</td>
            <td>@Html.Encode(item.L1_Manager)</td>
        </tr>
            <tr>
            <td>L2 Manager</td>
            <td>@Html.Encode(item.L2_Mnager)</td>
        </tr>
            <tr>
            <td>CostCentre</td>
            <td>@Html.Encode(item.CostCentre)</td>
        </tr>
        }
    </table>
    </div>
4

2 回答 2

0
    model Approvals.Models.Detail

@{
ViewBag.Title = "Details";
//Layout = "~/Views/Shared/_Layout.cshtml";
}

@section Header {
@Html.ActionLink("Back", "PendingRequests", "Account", null, new { data_icon = "arrow-l", data_rel = "back" })
<h1>@ViewBag.Title</h1>
@Html.ActionLink("Log Off", "LogOff") 


}

<head>
 <link href="~/StyleSheet1.css" rel="stylesheet" type="text/css" />
    </head>
<div data-role="collapsible"  data-theme="b" data-content-theme="b">
    <h3>Employee Details</h3>
    <table class="td3">
        <tr>
            <td>Employee ID</td>
            <td>@Html.Encode(Model.EmpID)</td>
        </tr>
            <tr>
                <td>Short ID</td>
                <td>
                    @Html.Encode(Model.ShortID)
                </td>
            </tr>
            <tr>
            <td>Grade</td>
            <td>@Html.Encode(Model.Grade)</td>
        </tr>
            <tr>
            <td>Vertical</td>
            <td>@Html.Encode(Model.Vertical)</td>
        </tr>
            <tr>
            <td>Vertical Head</td>
            <td>@Html.Encode(Model.VerticalHead)</td>
        </tr>
            <tr>
            <td>L1 Manager</td>
            <td>@Html.Encode(Model.L1_Manager)</td>
        </tr>
            <tr>
            <td>L2 Manager</td>
            <td>@Html.Encode(Model.L2_Mnager)</td>
        </tr>
            <tr>
            <td>CostCentre</td>
            <td>@Html.Encode(Model.CostCentre)</td>
        </tr>
    </table>
    </div>
于 2013-04-24T08:31:31.097 回答
0
  1. 而不是详细信息模型对象的 var 类型,而是在“详细信息”操作中给出绑定视图的类型,即 Approvals.Models.Detail 的 IEnumerable。

  2. 如果未在 return View() 中提供,您的视图名称应与操作名称匹配。否则在“详细信息”操作中返回视图(“xxx”,详细信息模型)。

于 2013-04-23T10:19:48.233 回答