I am banging my head against this wall for some time, some help will be highly appreciated:
Let's say I we have a simple Model:
public class Contact {
public string FirstName { get; set; }
public string LastName { get; set; }
}
And a simple editor temple:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Rpdc.Models.Contact>" %>
FirstName: <% = Html.TextBoxFor(x => x.FirstName)%><br />
SecondName: <% = Html.TextBoxFor(x => x.LastName)%><br />
What I want to accomplish, is do display a list of editable Contacts, each with his own "save" button. If I do it this way:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IList<Rpdc.Models.Contact>>" %>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<% foreach(Contact c in Model) { %>
<% using(Html.BeginForm("UpdateContact", "Home")) { %>
<%=Html.EditorFor(x => c) %>
<input type="submit" value="save" />
<% } %>
<% } %>
</asp:Content>
It renders a list of editors for each object, but all the textboxes have identical id's ("c_FirstName" and "c_LastName" for each "Contact" object).
And this way:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IList<Rpdc.Models.Contact>>" %>
<asp:Content ID="Content4" ContentPlaceHolderID="MainContent" runat="server">
<% using(Html.BeginForm("UpdateContact", "Home")) { %>
<%=Html.EditorForModel() %>
<input type="submit" value="save" />
<% } %>
</asp:Content>
It renders a list of objects, but with only one save button that submits all the objects. (Works, but it's not what I need)
Is there a clean way to display a list of editors for a list of objects, with a separate "save" button for each of them and without elements having repeating id's?
Thanks