Reputation: 13
I have this model:
public class PostAddRequest
{
public int Id { get; set; }
public string Title { get; set; }
public string FeaturedImagePath { get; set; }
public HttpPostedFileBase FeaturedImage { get; set; }
}
Now, in the controller I cannot find how to populate the HttpPostedFileBase
property, so that the input type field would be populated.
Upvotes: 0
Views: 1103
Reputation: 218877
This can't be done, because it shouldn't be done. Change your approach.
You don't want to pre-populate a file input from the server. Even if it were possible, consider what would be involved in a scenario where the user submits the form without changing the file:
Take a step back and re-think the approach. The file input is initially empty and there for the purpose of the user selecting a new file if they want to.
To show the user that a file already exists on the server, provide a UI separate from the file input. It could be something as simple as this:
<a href="/files/123">Filename.ext</a> (click to download)
<a href="/files/123/delete">Delete?</a>
Select a new file: <input type="file" name="file" />
Or anything along those lines of functionality. Basically you have three operations available:
Those are separate operations, invoked by separate UI elements. The file input only covers one of those operations.
Upvotes: 2