KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a view with a grid that contains items added to a workstation. The user can select an item from a drop down list and click an action link which calls a controller that adds that item to the workstation. I can make it work by reading the FormCollection object in the Post action of the controller. <p> <% using(Html.BeginForm("AddItem", "Home")) { %> <label for="ItemID">Item:</label> <%= Html.DropDownList("ItemID", Model.ItemsList) %> <%= Html.Hidden("WorkstationID", Model.Workstation.RecordID) %> <input type="submit" value="Submit" /> <% } %> </p> [AcceptVerbs(HttpVerbs.Post)] public ActionResult AddItem(FormCollection formValue) { long workstationId = Convert.ToInt64(formValue["WorkstationID"]); long itemId = Convert.ToInt64(formValue["ItemID"]); Workstation workstation = itilRepository.FindWorkstation(workstationId); Item item = itilRepository.FindItem(itemId); itilRepository.AddItem(workstation, item); itilRepository.Save(); return Content("Item added successfully!"); } What I want to do is be able to submit the two parameters the workstationId and itemId to the controller using Ajax.ActionLink and have the new item that was added get inserted into the grid. I am rendering the grid like this: <table> <tr> <th></th> <th> Name </th> <th> Service Tag </th> <th> Serial Number </th> </tr> <% foreach (var item in Model.Items) { %> <tr> <td> <%= Html.ActionLink("Edit", "ItemEdit", new { id = item.RecordID }) %> | <%= Html.ActionLink("Details", "ItemDetails", new { id = item.RecordID })%> </td> <td> <%= Html.Encode(item.Name) %>
Tags (comma-separated)
Save Edits
Cancel