I have created an Admin area in my MVC 4 application. Under Views Folder called UserManage
, I am using Grid.MVC to list out users (sets of 5) over several pages. In the Grid I am listing out the users details for viewing by Admin, and have added:
EDIT
link.CREATE
button.DELETE
button (to be used in conjunction with the checkbox for each row).My User Details page is under my Admin Area in the following path: Project\Areas\Admin\Views\UserManage\Index.cshtml
. On my EDIT
liniks, I am attempting to pull up the view at Project\Areas\Admin\Views\UserManage\Edit.cshtml
and pass the individual UserID
to the View to pull up that users data.
In my current code below, my browser resolves to http://localhost:62517/Admin/UserManage/Edit?Length=4
with an IIS 8.0 404 Error (Controller cannot find UserID). However if I manually change the Length
to Id
as follows, everything works as intended and I end up on my Edit
view: http://localhost:62517/Admin/UserManage/Edit?Id=4
.
Here is my grid code for the Index.cshtml
page. Does anyone know what I need to modify on my Html.ActionLink()
so my route will resolved to ?Id=
instead of ?Length=
?:
<div class="overflowPrevention">
@Html.Grid(Model).Columns(columns =>
{
columns.Add().Encoded(false).Sanitized(false).SetWidth(30).RenderValueAs(o => @Html.CheckBox("checked", false));
columns.Add().Encoded(false).Sanitized(false).RenderValueAs(o => Html.ActionLink("Edit", "Edit", "Edit", new { id = "1" }));
}).AutoGenerateColumns()
</div>
You are using the wrong overload.
@Html.ActionLink(string linkText, string actionName, string controllerName, object htmlAttributes)
instead of
@Html.ActionLink(string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)
You can just pass null for htmlAttributes if you don't need to use them:
Html.ActionLink("Edit", "Edit", "UserManage", new { id = "1" }, null)
I'm not sure why you are using Edit, Edit, Edit though. I think that was a typo so I have changed it to use UserManage as the controller name.