user8311110
user8311110

Reputation:

How to get id value from Table

I'm new to mvc please help me how can i get id value from the table.Here im using IModelBinder

<table class="table">
    <tr>
        <td>EmpId</td>
        <td>Email</td>
        <td>Action</td>
    </tr>
    @foreach(Employee emp in Model.GetEmployee)
    {
        <tr>
            <td>@emp.Emp_Id</td>
            <td>@emp.Email</td>

            <td>@Html.ActionLink("Edit", "GetById", "EmployeeManagement", new {id=emp.Emp_Id})</td>
        </tr>
    }
</table>

When i Bind as new {id=emp.Emp_Id} Im getting Length as 18 for every column Like http://localhost:9426/EmployeeManagement/GetById?Length=18

Upvotes: 1

Views: 610

Answers (2)

Jilani pasha
Jilani pasha

Reputation: 407

Replace Action Link with this

@Html.ActionLink("Edit", "GetById", "EmployeeManagement", new { id = emp.Emp_Id }, new { })

Upvotes: 0

Eliasib13
Eliasib13

Reputation: 61

You're using the Html.ActionLink overload with 4 parameters, which the last one is an Object. This parameter refers to route parameters (see here: https://msdn.microsoft.com/en-us/library/dd492936(v=vs.118).aspx).

If you want to refer to the HTML parameters you need the overload with 5 parameters (two last are Objects), where 4th parameter still the route parameters (which you can leave as blank object {}) and the 5th is the HTML parameters (which are specified as query parameters) (see more here: https://msdn.microsoft.com/en-us/library/dd492124(v=vs.118).aspx).

So, you could try to substitute your @Html.ActionLink expression like this (notice the blank object addition on the 4th parameter):

<td>@Html.ActionLink("Edit", "GetById", "EmployeeManagement", new {}, new {id=emp.Emp_Id})</td>

Upvotes: 2

Related Questions