I am new to this community and I downloaded and installed the MVC4 along with the Web API template.
Then, I created a new solution with the Web Api template.
I created a new Controller and View, which is basically a html page which contains a form which creates a Post towards another Controller, which is basically a copy of the ValuesController, which is created when selecting the Web API Template of the MVC4
solution.
When I click the submit button a download window is shown and immediately an error is raised saying that the download failed. But I only wanted to create a post and possible feedback shown in the iframe named result, which is set as target attribute in the
form-Tag.
I tried to modify the Post Method with a return value of HttpResponseMessage and the sample with void, both show the exact behavior.
I don't know where the problem might be. Maybe someone had the same issue and resolved it? Or any suggestion?
Thanks for the reply. The project I created is used to upgrade an existing project from the original Web API project at Codeplex. There, the HTML works flawless.
The goal is to receive a very basic, but conform HTTP Post from SAP. (Which works with the old WebApi project)
If AJAX is now required to create a Post, I am not sure, if the Web API can handle non-Ajax HTTP Posts from SAP.
Form POST is gonna work and Web API sure can handle that but if the result is XML or JSON, you will see a page not very useful. SO it is for the sake of client experience that AJAX is preferred.
I think you need to use fiddler to see what error comes back and also do server side debugging to catch the error and update your question.
Check jquery.ajaxSubmit to submitting the form and recieving the respose through ajax. The beauty of this plugin is that you can also submit a a multipart form
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
This wouldn't work. As I wrote in the initial post of this thread, this WebApi project is used to receive a basic, non-ajax/jquery, html-Post from SAP.
This project has been realized in the previous version of webapi (when it was not part of mvc), but we decided to port it to the new version, as the WebApi template is smaller, better to maintain. The posted html-code was working flawless in the pre-mvc
version of WebApi.
This wouldn't work. As I wrote in the initial post of this thread, this WebApi project is used to receive a basic, non-ajax/jquery, html-Post from SAP.
I think you need to explain a little more. What are you trying? As stated above by aliostad that Web API is intended to return you data which can be used variety of application(including SPA upshot.js)
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
JanGD
0 Points
14 Posts
Post Method results in unexpected download, which fails
May 04, 2012 08:14 AM|LINK
Hello all,
I am new to this community and I downloaded and installed the MVC4 along with the Web API template.
Then, I created a new solution with the Web Api template.
I created a new Controller and View, which is basically a html page which contains a form which creates a Post towards another Controller, which is basically a copy of the ValuesController, which is created when selecting the Web API Template of the MVC4 solution.
The code of the html looks like this:
@{ Layout = null; } <!DOCTYPE html> <html> <head> <!-- <meta name="viewport" content="width=device-width" /> --> <title>webProxy Tester</title> </head> <body> <form action="http://localhost/MyController/api/MyController" enctype="text/html" method="post" target="result"> POST data: <br /> <textarea name="person" cols="100" rows="20"></textarea> <input type="submit" value="Submit" /> <br /><br /> <a href="http://localhost/MyController/api/MyController" target="result">Get resource</a> <br /><br /> <iframe name="result" width="1000px" /> </form> </body> </html>When I click the submit button a download window is shown and immediately an error is raised saying that the download failed. But I only wanted to create a post and possible feedback shown in the iframe named result, which is set as target attribute in the form-Tag.
I tried to modify the Post Method with a return value of HttpResponseMessage and the sample with void, both show the exact behavior.
I don't know where the problem might be. Maybe someone had the same issue and resolved it? Or any suggestion?
Thanks in advance
~Jan
aliostad
Member
228 Points
55 Posts
Re: Post Method results in unexpected download, which fails
May 04, 2012 10:06 AM|LINK
An HTML form is not really meant for working directly with Web API and handling results.
You need to use AJAX to communicate with the Web API. For a working example, have a look at here:
http://www.west-wind.com/weblog/posts/2012/Mar/09/Using-an-alternate-JSON-Serializer-in-ASPNET-Web-API
JanGD
0 Points
14 Posts
Re: Post Method results in unexpected download, which fails
May 04, 2012 10:26 AM|LINK
Thanks for the reply. The project I created is used to upgrade an existing project from the original Web API project at Codeplex. There, the HTML works flawless.
The goal is to receive a very basic, but conform HTTP Post from SAP. (Which works with the old WebApi project)
If AJAX is now required to create a Post, I am not sure, if the Web API can handle non-Ajax HTTP Posts from SAP.
aliostad
Member
228 Points
55 Posts
Re: Post Method results in unexpected download, which fails
May 04, 2012 10:55 AM|LINK
Form POST is gonna work and Web API sure can handle that but if the result is XML or JSON, you will see a page not very useful. SO it is for the sake of client experience that AJAX is preferred.
I think you need to use fiddler to see what error comes back and also do server side debugging to catch the error and update your question.
JanGD
0 Points
14 Posts
Re: Post Method results in unexpected download, which fails
May 07, 2012 08:13 AM|LINK
As the Post-Method in the Controller can be of return type void, it still gives the problem.
As I understand your post, if "nothing" is returned (only HTTP 200, 404, etc), it shouldn't give a problem?
Funny part is, the a href tag with the link to the get is working as intended and the result is shown in the iframe.
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Post Method results in unexpected download, which fails
May 19, 2012 06:06 PM|LINK
Check jquery.ajaxSubmit to submitting the form and recieving the respose through ajax. The beauty of this plugin is that you can also submit a a multipart form
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
JanGD
0 Points
14 Posts
Re: Post Method results in unexpected download, which fails
May 21, 2012 07:45 AM|LINK
This wouldn't work. As I wrote in the initial post of this thread, this WebApi project is used to receive a basic, non-ajax/jquery, html-Post from SAP.
This project has been realized in the previous version of webapi (when it was not part of mvc), but we decided to port it to the new version, as the WebApi template is smaller, better to maintain. The posted html-code was working flawless in the pre-mvc version of WebApi.
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Post Method results in unexpected download, which fails
May 21, 2012 06:19 PM|LINK
I think you need to explain a little more. What are you trying? As stated above by aliostad that Web API is intended to return you data which can be used variety of application(including SPA upshot.js)
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
JanGD
0 Points
14 Posts
Re: Post Method results in unexpected download, which fails
May 22, 2012 07:28 AM|LINK
Sure, the process is like this
1. SAP: Create IDoc as XML
2. SAP: Send IDoc over HTTP Post
3. WebApi: get HTTP Post Content (IDoc as XML, in Point 1)
4. WebApi: forward the IDoc from 3 to a webservice
For testing, the html page is used to "simulate" a post from Step 2.
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Post Method results in unexpected download, which fails
May 22, 2012 05:13 PM|LINK
Then what do you expact from web api.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD