When I request Views from the MVC backend, I need more than just the content:
public class CustomJsonViewResult
{
public string Subject { get; set; }
public ActionResult View { get; set; }
}
As time goes on, this class will become more complex.
To implement this in a Controller method, you can do:
public JsonResult Person()
{
return Json(new CustomJsonViewResult
{
View = View(),
Subject = "Update an existing person"
}, JsonRequestBehavior.AllowGet);
}
The subject value should be determined dynamically in the future instead of being static.
In my AngularJS directive, I have 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 code works when returning the ActionResult directly, but currently I am encountering 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)
When I log viewData to console, it shows:
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
To Summarize:
Any thoughts on why I'm getting this Cannot read property 'ownerDocument' of undefined error? Everything seems to be as expected.