0
votes

All, I am trying to edit the data using MVC4.

When I click on Edit link - I could see the param name AND Value getting appended in the querystring but in controller I am unable to get the value for selected row

Controller Code

public ActionResult Edit(string id)
        {
          PhonebookModel PHm =   _phList.Find(x => x.ID == id);
            return View(PHm);
        }

Here in controller, I am getting ID as null.. Any clue what I am doing wrong?

Note: I can see the Edit screen but all controls are empty.

Thanks in advance. cshtml code that generates Edit link @model IEnumerable

@{ ViewBag.Title = "Index"; }

Index

@Html.ActionLink("Create New", "Create")

@Html.DisplayNameFor(model => model.FirstName) @Html.DisplayNameFor(model => model.Last Name) @foreach (var item in Model) { @Html.DisplayFor(modelItem => item.FirstName) @Html.DisplayFor(modelItem => item.LastName) @Html.ActionLink("Edit", "Edit", new { ID = item.ID}) | @Html.ActionLink("Details", "Details", new { ID = item.ID }) }
1
Please post the helper code generating the linkJack
@Index.cshtml I have following code that defines link @Html.ActionLink("Edit", "Edit", new { ID= item.ID}) |Amit
@Amit - There is no edit link there. Or any link that passes an id. What code generates the link to the Edit action?Simon C
@Jack- I have added the code that generates the Edit linkAmit
_phList.Find(x => x.ID == Request["ID"]) and I am able to get the values... Is this a proper way to get value selected from UI to controller ?Amit

1 Answers

1
votes

I think the parameter is case sensitive, try changing your ActionLink to:

@Html.ActionLink("Edit", "Edit", new { id = item.ID})