I'm trying to post back from a strongly typed view to my controller.
the problem is there are a couple of fields in the model that i dont want to allow the user to edit. ideally i just want to display them as labels but when i do that they're null when posted...
here's the relevant view code: this looks how i want it to look i.e. firstname and lastname are labels
<td width="75px"><%: Html.DisplayFor(model=>model.FirstName, new{disabled="true"}) %></td>
<td width="75px"><%: Html.DisplayFor(model => model.LastName)%></td>
<td width="100px"><%: Html.LabelFor(model => model.EmailAddress) %></td>
<td width="75px"><%: Html.TextBoxFor(model => model.EmailAddress) %></td>
<td><%: Html.ValidationMessageFor(model => model.EmailAddress) %></td>
Model looks like this:
public class PersonModel { [Required] [DisplayName("First Name")] public string FirstName { get; set; }
[Required]
[DisplayName("Last Name")]
public string LastName { get; set; }
[DisplayName("Email Address")]
public string EmailAddress { get; set; }
}
the controller looks like this:
[HttpPost] public ActionResult RsvpToInvitation(PersonModel submittedRsvp) {...}
I've stripped a fair amount of code out of all of these... basically my question is how can i display a model property as a label and still post it back to the controller?