Question

My problem is in view...Please give me new view which suits my database and action.

My details table:

Details table

Passing request id using html action link:

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

clicking on the link we should get details corresponding to the link from database.

Action method:

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());
    }

Hope my problem is returning view and designing view. My requirement is I want details for particular id and should display them in the below designed view. I am able to check the ids in var details model and then I have to read remaining fields from databse and disply the fields in my view.I am notable to do it. Please help me.

View:

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>
Was it helpful?

Solution

    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>

OTHER TIPS

  1. Instead of var type for detailsModel object give type what is bound to view i.e. IEnumerable of Approvals.Models.Detail in "Details" action.

  2. your view name should match action name if not supplied in return View(). else return View("xxx", detailsModel ) in "Details" action.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top