开发者

Call MVC2 action controller from Webforms class code-behind

开发者 https://www.devze.com 2023-03-19 18:08 出处:网络
Is it possible for a Webforms class to call an MVC2 action controller that returns a string? My Webforms class is a proxy class for an external webservice, and so I have no JavaScript code - the prop

Is it possible for a Webforms class to call an MVC2 action controller that returns a string?

My Webforms class is a proxy class for an external webservice, and so I have no JavaScript code - the properties thatI need must be retr开发者_如何学JAVAieved in the code-behind!

The proxy class is in use by other projects in my solution, so I preferably do not want to move it into the MVC project. The proxy gathers a few properties, among them the full path to a PDF.

The PDF has not yet been generated when the proxy needs it, and the responsibility of generating it lies on the MVC project. Because of this, I need to call an action controller that generates a PDF and returns its path.


You shouldn't really mix webforms and MVC. Better to put them in separate apps & communicate via HTTP/REST/SOAP, etc.

If it's an external web service, can you not add it again to your MVC app?

If you can't modify the proxy at all, then add a webforms page to your mvc app & have it inherit from the proxy. create the controller & action to create the pdf the redirect back to the webform.

Simon


The solution that worked for me was to use the WebRequest class, which MSDN has a good article on here: How to: Send Data Using the WebRequest Class

0

精彩评论

暂无评论...
验证码 换一张
取 消