Apr 08, 2016, 1:01 PM
[CLOSED] FileUploadField gets cleared even if POST did not happen
Hi
I have strange situation with FileUploadField. It gets cleared even if POST did not happen. I prevent post with before handler like in following example:
View:
I have strange situation with FileUploadField. It gets cleared even if POST did not happen. I prevent post with before handler like in following example:
View:
<script>
var returnValue = true;
function doValidation() {
returnValue = !returnValue
return returnValue;
}
</script>
@Html.X().ResourceManager()
@(
Html.X().Window()
.Items
(
Html.X().FormPanel().ID("mainForm")
.Items
(
Html.X().FileUploadField().ID("fileUpload").ClearOnSubmit(false)
)
)
.Buttons
(
Html.X().Button().Text("OK").ID("btnOk").Disabled(false)
.DirectEvents
(
de =>
{
de.Click.Before = "return doValidation();";
de.Click.IsUpload = true;
de.Click.FormID = "mainForm";
de.Click.Url = Url.Action("DoAction");
de.Click.ExtraParams.Add(new Parameter("formValues", "this.up('window').down('form').getForm().getFieldValues(false)", ParameterMode.Raw));
de.Click.EventMask.ShowMask = true;
}
)
)
)
Controller:public class DefaultController : Controller
{
// GET: Default
public ActionResult Index()
{
return View();
}
public ActionResult DoAction()
{
FileUploadField fileUploadField = this.GetCmp<FileUploadField>("fileUpload");
if (fileUploadField.HasFile)
{
string fileName = fileUploadField.PostedFile.FileName;
X.Msg.Notify(new NotificationConfig
{
Icon = Icon.Accept,
Title = "Information",
Html = string.Format("Poste file {0}", fileName),
HideDelay = 4000
}).Show();
}
else
{
X.Msg.Notify(new NotificationConfig
{
Icon = Icon.Error,
Title = "Error",
Html = "No file posted!",
HideDelay = 4000
}).Show();
}
DirectResult result = new DirectResult();
result.IsUpload = true;
return result;
}
}
You will notice that ClearOnSubmit works (text box part in FileUploadField doesn't get emptied), but file is actually gone. We have tried to have similar situation like in real project, only here first time it will simply not let you post (in real project there are several complex checks, so we wanted to avoid it and to make sample as simple as possible).
Last edited by fabricio.murta; Apr 11, 2016 at 2:09 PM.
Reason: [CLOSED]