PDA

View Full Version : [CLOSED] MVC controller problem in 2.0



gets_gui
Apr 05, 2012, 6:26 PM
Hi,

We were using 1.3 with MVC.
And I am trying to port the code from 1.3 to 2.0.

And there is a FileUploadField upload a file.
Here is the view:

<ext:FileUploadField ID="fileUploadField" Name="upload" runat="server" Width="200" Icon="Attach" ButtonText="Upload...">
<Listeners>
<Change Handler="Upload();"/>
</Listeners>
</ext:FileUploadField>
And here is the javascript for uplaod:

App.formPanel.getForm().url = "/Home/Upload";
App.formPanel.getForm().submit();

And the controll code as following:

[AcceptVerbs(HttpVerbs.Post)]
public void Upload()
{
...
}

It is working fine in 1.3, we got ext.js error in 2.0.
"Microsoft JScript runtime error: Exception thrown and not caught".
And the javascript code snippet from ext.js:

try{return decodingFunction(json)}
The json is empty string.

Please advise, thanks!

Daniil
Apr 05, 2012, 9:05 PM
Hi,

I was unable to reproduce using the example below.

Example View

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ext.Net.MVC v2 Example</title>

<script type="text/javascript">
var upload = function () {
App.FormPanel1.getForm().url = "/Test/Upload";
App.FormPanel1.getForm().submit();
};
</script>
</head>
<body>
<ext:ResourceManager runat="server" />
<ext:FormPanel ID="FormPanel1" runat="server">
<Items>
<ext:FileUploadField runat="server">
<Listeners>
<Change Handler="upload();" />
</Listeners>
</ext:FileUploadField>
</Items>
</ext:FormPanel>
</body>
</html>

Example Controller Action

public ActionResult Upload()
{
FormPanelResult r = new FormPanelResult();
r.IsUpload = true;
HttpPostedFileBase file = Request.Files[0];
file.SaveAs("c:\\Work\\Solutions\\Work2MVC\\uploaded");

return r;
}

Please inspect a response of uploading request. There should be something like this:

<textarea>{success:true}</textarea>

Is there no exception?

If the issue persists, please provide a full sample to reproduce.

gets_gui
Apr 05, 2012, 9:26 PM
Daniil,

Thanks you for the help.

Actually we don't want to return ActionResult.

I just found out the solution for the problem from sencha forum just in case someone has similar problem.
http://www.sencha.com/forum/showthread.php?189428-file-upload-with-extjs-4-with-java

Please close this ticket.

gets_gui
Apr 10, 2012, 8:08 PM
Hi,

I noticed that if I use the Change event, the handler is called twice.
The first time, it is called with the correct file name in
Request.Files[0].FileName;
the file name is an empty string for the second time.

It happened in the example Daniil put here as well.


<ext:FileUploadField runat="server">
<Listeners>
<Change Handler="upload();" />
</Listeners>
</ext:FileUploadField>

Is there anyway to trigger the call once without the empty file name?

Daniil
Apr 10, 2012, 8:31 PM
I was able to reproduce the issue in IE8 only. The Change event triggers once in IE9, FireFox, Chrome.

Can you confirm there is the same behavior on your side?

gets_gui
Apr 10, 2012, 8:39 PM
Yes, I have the same behaviour.
I had to vlidate based on the filename.

Daniil
Apr 11, 2012, 8:16 AM
For now, we can suggest the following workaround.

<Change Handler="if (!Ext.isEmpty(newValue)) {
upload();
}" />

Though we are investigating further.

gets_gui
Apr 11, 2012, 2:38 PM
Fair enough.

Thanks!

Daniil
Apr 16, 2012, 3:47 PM
We have added the fix to SVN (generally, the same as a workaround I've suggested).

And reported to ExtJS team.
http://www.sencha.com/forum/showthread.php?195984

gets_gui
Apr 17, 2012, 4:17 PM
I checked out the SVN and tested it.
It works, thanks!

Daniil
Apr 17, 2012, 4:19 PM
By the way, any comments on this?
http://www.sencha.com/forum/showthread.php?195984&p=781083&viewfull=1#post781083

What OS do you test with?

gets_gui
Apr 17, 2012, 4:31 PM
We are using Windows XP professional and IE8.
I hope Schena team is still supporting it...

Daniil
Apr 17, 2012, 5:02 PM
Yes, it's still supported.

Are you able to reproduce the problem using my example which I posted in that thread?

gets_gui
Apr 17, 2012, 6:39 PM
I am able to reproduce with your code.
Two popups with "change" message.

Daniil
Apr 17, 2012, 6:47 PM
Ok, thanks.

Hopefully, ExtJS team will finally reproduce as well :)