Mahesh Bodepudi

Mahesh Bodepudi

  • NA
  • 90
  • 54.8k

Edit link passing null value when click on that link

Dec 15 2016 8:22 AM
Hi,
In my view code I have written code for editing a record
 
<td> @Html.ActionLink("Edit", "Edit","PO", new { id = item.Sl_No }) |
@Html.ActionLink("Details", "Details", new { id = item.Tracking }) </td>
<td>@item.Tracking</td>
<td>@item.Project_No</td>
<td>@item.Project_Phase</td>
<td>@item.Project_No_Description</td>
<td>@item.Requester</td>
<td>@item.Date_Requested</td>
 
When loading the data I am able to see the fields mentioned in the script,
But In controller code
 
public ActionResult Edit(int SlNo)
{
var viewModel = new POViewModel();
viewModel.Order = PODb.orders.Single(x => x.Sl_No == SlNo);
viewModel.Order = (order)PODb.orders.Where(x => x.Sl_No == SlNo);
return View(viewModel);
}
 
Here In the above code I am getting the parameter value as null as it is throwing the below exception
"

The parameters dictionary contains a null entry for parameter 'SlNo' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Edit(Int32)' in 'PurchaseOrder.Controllers.POController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters

 Could any one please help me how to rectify this one?

Answers (6)