开发者

Programmatically invoking asp.net mvc controller action from webforms page

开发者 https://www.devze.com 2023-01-16 10:19 出处:网络
Is it possible to invoke an action on asp.net mvc controller programmatically from a classic webforms page that is not handled by MVC but running in the same web app开发者_运维技巧lication?

Is it possible to invoke an action on asp.net mvc controller programmatically from a classic webforms page that is not handled by MVC but running in the same web app开发者_运维技巧lication?

We have a mixed asp.net web application: webforms for page rendering and mvc for ajax calls. But we want to render some MVC views from webform page on the server via the code (not a web request)...

Currently we are doing a web request locally to get the rendered view: is it the right/only way?


You should be able to invoke a an action on an MVC controller and render the returned HTML by performing an Ajax request with the appropriate URL.

<script type="text/javascript>

        $.get("http://yourhost/Controller/Action/", function(data){
            $("#divToRenderTo").html(data);
        });

</script>

I don't think it'd be possible to invoke actions on a controller from a webform's code behind as they're using different frameworks to operate.

0

精彩评论

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