I have a Edit View generated by VS 2010 (code below). I don't want the user to see the ListID, so i commented it out.
What happens is that if I comment the <%: Html.TextBoxFor(model => model.ListID) %> line, when I hit submit, the Controller instead of receiving something like a DSList with name="x" and listID=10, always gets the listID=0.
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<DomainModel.Entities.DSList>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Edit
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>
Edit</h2>
<% using (Html.BeginForm())
{%>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-field">
<%--<%: Html.TextBoxFor(model => model.ListID) %>--%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Name) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Name) %>
<%: Html.ValidationMessageFor(model => model.Name) %>
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
<% } %>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div>
</asp:Content>
Controller:
[HttpPost]
public ActionResult Edit(DSList l)
{
// l always comes with the id equal to 0.
... logic ...
}
What can I do to receive the correct object?
Thank you