httppostedfilebase null after reloading the page, (image upload)

Asked

Viewed 81 times

0

Is there any way I won’t lose data from HttpPostedFileBase? my action makes a check, and in case of failure the page recharges with the image in the form and I have to make the call again, then HttpPostedFileBase will null unless I choose the image again.

@{
Dictionary<string, object> htmlAttributes = new Dictionary<string, object>();
htmlAttributes.Add("id", "delivery-form");
htmlAttributes.Add("class", "middle-forms");
htmlAttributes.Add("enctype", "multipart/form-data");
}

@using (Html.BeginForm(actionName, "DeliveryService", ViewBag.Routes as RouteValueDictionary, FormMethod.Post, htmlAttributes @*new { @id = "delivery-form", @class = "middle-forms" }*@))
{

First call: inserir a descrição da imagem aqui

Second Call: inserir a descrição da imagem aqui

UPDATE

One solution I came up with was to use a Session to save data from HttpPostedFileBase, being like this:

Session["ImportFile"] = ImportFile;
  • 2

    I believe that it does not exist, because if it were possible to assign a value to a input of the kind file from the server we would have a serious browser security failure.

  • 1

    Maybe you can do a partial validation before posting the image?

  • 1

    You could do the validation in the client...

  • We had already talked before here in the project about this validation, the best way will be to change even.

  • suddenly save the item to localstorage and resend to Submit

  • I’m trying the @Rafaellarrosa tip from localStorage, I’m trying to send it to Submit now.

Show 1 more comment

1 answer

-1

I do so, create a table that saves image information, such as, path, name, extension, etc... so you can upload via ajax, using angum plugin, and return its id, so in Submit you send this id along with the model, and deal with the backend

  • I think this is not a good solution because I am choosing the image to be saved along with the form data, besides the fact that I have to create a table to save the data after this save the image before the form. I use the image path to load it after being saved, but at this point it has not been saved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.