I just look at ASP.Net MVC3 and in one of the automatically created views for Create, it uses "Html.EditorFor (model => model.User)" to provide a text box for the user to enter the username. Ideally, I would automatically populate this with @ User.Identity.Name.
What is the right way to achieve this? Does Html.EditorFor allow me to automatically populate it in the view, or should I install it on the controller when transferring it?
I found that if I change the Create method in the controller, then:
public ActionResult Create() { return View(); }
For this:
public ActionResult Create() { MyObject myobject = new MyObject(); myobject.User = User.Identity.Name; return View(myobject); }
It seems to work. Is this the right way to do this?
Thanks in advance for any confirmation that I am doing this correctly.
Darren
source share