I have a simple from that a user will complete to submit a “newswire”. When the form loads on the create view I want the author Input to auto populate with the logged in username inside the text box in the view. Can anyone comment on what I’m doing wrong?
my model:
public class NewsWire
{
public int ID { get; set; }
public int VendorID { get; set; }
public DateTime Date { get; set; }
public string Subject { get; set; }
public string NewsItem { get; set; }
//public string Author { get; set; }
public string Author
{
get
{
return System.Web.HttpContext.Current.User.Identity.Name;
}
}
}
In the form for the author section I have this:
<div class="editor-label">
@Html.LabelFor(model => model.Author)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Author)
@Html.ValidationMessageFor(model => model.Author)
</div>
I have tried several variations but still not getting it right. Any help would be appreciated.
Model:
and inside the controller action that renders this view populate the
Authorproperty from the currently logged in user: