Initialize MVC View's DisplayFor element with a value to display. Simple, right?

26 Views Asked by At

MVC App I am Creating a row for a table. It is defined as a Model. The value of one of the fields is determined during a 'login' and is available for use.

That value should be displayed when the Create view is rendered on exit from the 'create(GET)' action and it should be saved as is to the data table by the POST.

So, bound to the model and prepopulated display element sounds like a job for Html.DisplayFor. Only it seems it is not.

How do we set the initial value in the DisplayFor statement. Barring that, how do we get data to the screen from the GET action for capture and saving during the Create(POST)?

1

There are 1 best solutions below

0
On

I have to write more than one of these a year. I can just pass a populated model instance in the return View(modelInstance).

That's my stupidity quota for the day, hopefully.