开发者

ASP.NET MVC 2 - Repopulating file inputs in an edit view

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 t开发者_StackOverflowhe 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?


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜