4
votes

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 application?

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?

1

1 Answers

1
votes

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.