0

Is there a way to repopulate a form's file inputs in an Edit action's view? I'm using the same editor template for both my Create and Edit actions, and would like it so that when the form comes up during editing, the file input fields are automatically repopulated from the view model.

If so, the file names would come from the back end (since the files associated with the model are already in the system). With that being the case, would they still be considered HttpPostedFileBase objects, even though they didn't originate from the user's machine?

Major Productions
  • 5,914
  • 13
  • 70
  • 149

1 Answers1

0

when you have your edit action you should pass model to view again:

//Get
public ActionResult Edit(int id){
YourModelOrEntity model = load content here
return View(model);
}
//[get]
public ActionResutl Edit(MyModel model){
if(! ModelState.IsValid) return View(model);  //<-  this is how you pass it back to the user
}
cpoDesign
  • 8,953
  • 13
  • 62
  • 106
  • That didn't address my problem at all. I know that I have to pass my model to the view. What I AM asking about is how to handle whatever files may be part of the model in the view. Since I'm editing a model, these files already exist in the system. How do I pass them back to my view so they populate the form's file inputs? And, since there's a possibility that the files won't be changed, would they still be considered HttpPostedFileBase objects since they wouldn't be coming from the user's machine at that point? – Major Productions Aug 25 '11 at 11:40
  • Add the file name to dataview or model where you put the file name from request and chceck if the viewdata (model) is not empty... – cpoDesign Aug 26 '11 at 19:10