I’m trying to implement something like this:
<div> <table> <thead> <tr> <td>Port name</td> <td>Current port version</td> <td>New port version</td> <td>Update</td> </tr> </thead> <% foreach (var ip in Ports) { %> <tr> <td> <%= ip.PortName %> </td> <td> <%= ip.CurrentVersion %> </td> <td> <%= ip.NewVersion %> </td> <td> <asp:Button ID='btnUpdate' runat='server' Text='Update' CommandArgument='<% ip.PortName %>' /> </td> </tr> <% } %> </table> </div>
The button’s CommandArgument property is where my code complains about not being able to resolve symbol ip. Is there any way to do what I’m trying to do?
You don’t want to use a Webforms button in ASP.NET MVC. MVC is a completely different way of working, and you no longer have the WebForms abstraction.
You have 2 different options you can either replace your asp:Button with an input tag or use a standard hyperlink instead. If you use the input option then you will need to wrap in a form element. The form action should point to a Controller action.