I have a foreach loop that generates a table row for each item in an array of Business objects in the BusinessList view.
Here’s my Business object:
public class Business
{
public long BusinessID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
and here’s the Razor foreach loop:
@foreach (var item in Model)
{
<tr>
<td>
<div class="editor">
<div class="editor-label">
@Html.DisplayFor(modelItem => item.Name)
</div>
</div>
</td>
<td>
<div class="editor">
<div class="editor-label">
@Html.DisplayFor(modelItem => item.Description)
</div>
</div>
</td>
<td>
@Html.ActionLink("Edit", "EditBusiness")
</td>
</tr>
}
What I want to do is capture the BusinessID associated with the row in which the user clicks on the “Edit” button. The BusinessID value will need to be available to the EditBusiness view. I’d rather not use the querystring. Is there some way to set a ViewData, TempData, or ViewBag value when the user clicks the “Edit” link?
Rather than use pass the value as a querystring you could post the value by changing the edit link to a form with a hidden field for the ID and a submit button (styled like your edit link)
Or you could post via ajax.