When requesting Views from the MVC backend, I would like to receive more information than just the View content:
public class CustomJsonViewResult
{
public string Subject { get; set; }
public ActionResult View { get; set; }
}
The above class would become complexer over time.
This would be created in a Controller method like this:
public JsonResult Person()
{
return Json(new CustomJsonViewResult
{
View = View(),
Subject = "Update an existing person"
}, JsonRequestBehavior.AllowGet);
}
There would be added BL logic to determine the subject, rather than the static value that's there now.
On the receiving client I have an AngularJS directive with a link like this:
link: function (scope, element, attrs) {
screensService.GetPartialView(attrs.view).then(function (viewData) {
var linkFunc = $compile(viewData.View);
var content = linkFunc(scope);
element.append(content);
});
}
This works when I return the ActionResult directly, but in the current set up I get this error:
typeError: Cannot read property 'ownerDocument' of undefined
at Function.Sizzle.contains (jquery-2.1.4.js:1430)
at Function.jQuery.extend.buildFragment (jquery-2.1.4.js:5147)
at jQuery.fn.extend.domManip (jquery-2.1.4.js:5387)
at jQuery.fn.extend.append (jquery-2.1.4.js:5218)
at PartialViewLoaderDirective.js:27
at processQueue (angular.js:14569)
at angular.js:14585
at Scope.$get.Scope.$eval (angular.js:15848)
at Scope.$get.Scope.$digest (angular.js:15659)
at Scope.$get.Scope.$apply (angular.js:15953)
If I log the viewData to console, I get this:
Object {Subject: "Update an existing person", View: Object}
Subject: "Update an existing person"
View: Object
MasterName: ""
Model: null
TempData: Array[0]
View: null
ViewBag: Object
ViewData: Array[0]
ViewEngineCollection: Array[2]
ViewName: ""
jQuery21400306884015444666152: 19
__proto__: Object
__proto__: Object
Summary
Any idea what the cause is of this Cannot read property 'ownerDocument' of undefined error? As far as I can see everything is available as expected.