2

I've got AngularJS application that is loosely wrapped by an Asp.Net MVC page. The AngularJS stuff ignores the Asp.Net and does its own routing, ng-includes, and so on, so pages are constructed from html partials that Asp.Net knows nothing about.

I've run into a situation where it would be very useful to have an Asp.Net control / MVC extension in one of my pages, but the pages are deep in Angular land. Is there any practical way of getting this working without restructuring the whole application?

This is sort of what I'm trying to accomplish:

index.cshtml:

<body ng-app="App" ng-controller="Controller">
    <div ng-include src="angularView.html">

angularView.html:

<div ng-include src="aspNetView.cshtml">

aspNetView.cshtml:

@Html.Something()

Obviously the ng-include aspNetView.cshtml won't work, but this is what I'm trying to do: Asp.Net stuff inside the Angular stuff.

(My specific use case is trying to put in a DevExpress grid using @Html.DevExpress().GridView(...), but the problem is still general)

1
  • please provide a sample code Commented Oct 20, 2013 at 23:58

2 Answers 2

1

You could return a partial view from an ASP.Net MVC controller, and then call the method from angular and render the returned HTML in a div or other container.

If this is just displaying data, it should work with little problem (it's just an ajax call like any other). If the rendered HTML has to interact with the rest of the page (e.g. angular $scope, etc.) it might be more complicated.

Sign up to request clarification or add additional context in comments.

1 Comment

Could you give an example? I'm wondering how to include a file uploader for MVC in angular form.
0

To call partial view in asp.net mvc5 using AngularJS write this way:

<ng-include src="'@Url.Action("method_name", "Controller_name")'"></ng-include>

And also remember your controller method must return this way:

return PartialView("~/Views/Angular/TableAdd.cshtml");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.