I've created model Message
and showing list of these messages on Index
view of my site. The controller passes IEnumerable<Models.Message>
object to the view.
To display all these messages I'm iterating through them using @foreach
. But I also want to create form on the same Index
view to create new message. Seems to be easy task, but call to @Html.TextAreaFor(Model.Body)
gives me following error:
CS1061: 'System.Collections.Generic.IEnumerable<Models.Message>' does not contain a definition for 'Body' and no extension method 'Body' accepting a first argument of type 'System.Collections.Generic.IEnumerable<Models.Message>' could be found (are you missing a using directive or an assembly reference?)
Is it possible to create form based on Models.Message
, despite fact that view as created based upon IEnumerable<Models.Message>
?
My model is:
public class Message
{
[BsonId]
public ObjectId Id { get; set; }
public Citizen From { get; set; }
public Citizen To { get; set; }
[Required]
[AllowHtml]
public string Body { get; set; }
[ScaffoldColumn(false)]
public DateTime Date { get; set; }
public bool IsPrivate { get; set; }
}
EDIT: Frankly I don't want to create an additional model holding one message for form and list of messages for display, mostly since in form action controller I need to deal with this "extended" model. I think cleaner would be to have original Message
there.
But how?