Click event handler not working prepend parsed html - onclick

I have a element parsed from html template and i want to add a click event to it, it seems not working.
but when i add element like
$('#formatMe').click();
Here click is working but when
var formats = appAPI.resources.parseTemplate("formats.html",result);
$code=$(formats);
$('#vid_div').prepend($code);
But not on element from parseTemplate
I am writing click function in appAPI.ready like below
appAPI.ready(function($) {
$("#user-header").append("<div id='formatMe'>Download</div>");
$('#some-div-in-web-site').append("<div id='vid_div'></div>");
$('#formatMe').click(function(){
var url="myurl";
appAPI.request.get({
url: url,
onSuccess: function (data) {
var result=appAPI.JSON.parse(data);
var formats = appAPI.resources.parseTemplate("formats.html",result);
$('#vid_div').html('');
$code=$(formats);
$('#vid_div').prepend($code);
}
});
});
$('#close').click(function(){
alert("dont'click on me!!!");
});
});
Formats.html is like this
<div id="vid_formats">
<div id="close">×</div>
<div class="wrapper">
<h1>Download Links</h1>
<ul>
<% for (var i=0; i<vids.length; i++) { %>
<li>
<a id="format" href="<%=vids[i]['url'] %>"><%=vids[i]['type']%> <%=vids[i]['quality']%> - <%=vids[i]['size']%> </a>
</li>
<% } %>
</ul>
</div>
</div>
Still not able to fire click event, i am testing in firefox.

Foreword: Since the contents of the formats.html file and result array are not provided and it's also not clear from your example where the element with id close is defined, I created the scenario that I believe you are experiencing.
In the scenario I recreated, the click event handler worked as expected and I can see the alert. The following are the extension files I recreated and then tested in Chrome.
formats.html:
<div>
<ul>
<% for (var i=0; i<sites.length; i++) { %>
<li><%=sites[i].name%></li>
<% } %>
</ul>
</div>
<div id="close">Close</div>
extension.js:
appAPI.ready(function($) {
var result = {
sites:[
{url:' http://cnn.com ', name:'cnn'},
{url:' http://yahoo.com ', name:'yahoo'}
]
},
formats = appAPI.resources.parseTemplate("formats.html",result);
$('<div id="player"></div>').prependTo('body');
$code=$(formats);
$('#player').prepend($code);
$('#close').click(function(){
alert('clicked me');
});
});
[Disclosure: I am a Crossrider employee]

Related

send value to controller in angularjs and return array

I want send cod to controller and return array
When pressing a li you have to send a code to the controller, in this case I am setting the example 7. Once the code has arrived at the controller I will have a list that I have to show in a ng-repeat in table
SCRIPT
<script type="text/javascript">
var app = angular.module('myApp', [])
app.value('studentInfo', [
{ id: 1, name: 'Mahedee Hasan', credit: 20, semester: '8th' },
{ id: 3, name: 'Enamul Haque', credit: 15, semester: '7th' }
]);
app.controller('myCtrl', ['$scope', 'studentInfo', function ($scope, studentInfo, $http, $window) {
$scope.myClickList = function () {
$scope.studentInfo = studentInfo;
};
var Cod = "7";
$scope.myDataCountry = [];
$scope.ButtonCountry = function (Cod) {
$http.
post("/Country/Angular", { CodH: Cod }).success(function (result) {
$scope.myDataCountry = result;
});
};
}]
);
</script>
VIEW
<li><a data-toggle="tab" href="#calificaciones" ng-click="ButtonCountry ()"><span>Country</span></a></li>
<div ng-app="myApp" ng-controller="myCtrl">
<table class="table">
<tr>
<th>ID</th>
<th>Country</th>
</tr>
<tr ng-repeat="C in myDataCountry">
<td>{{C.ID}}</td>
<td>{{C.Country}}</td>
</tr>
</table>
</div>
CONTROLLER
public JsonResult Angular(string codCountry)
{
var country = (from a in dbCountry.Country
where a.CodPersona == codCountry
select a.Country).ToList();
return Json(country , JsonRequestBehavior.AllowGet);
}
I tried this and to
First, your li element isn't inside your app directive, which means it will not detect the function, you need to make sure that your li element is within the app scope
<!-- li is outside the scope -->
<li><a data-toggle="tab" href="#calificaciones" ng-click="ButtonCountry(1)"><span>Country</span></a></li>
<div ng-app="myApp" ng-controller="myCtrl">
<!-- end -->
<!-- li is within the scope -->
<div ng-app="myApp" ng-controller="myCtrl">
<ul>
<li><a data-toggle="tab" href="#calificaciones" ng-click="ButtonCountry(1)"><span>Country</span></a></li></ul>
<!-- end -->
of course, you need to alter your html elements, meaning ul parent of the li most be included as well.
your Action url is wrong, your controller shows that action name is CalificacionesAngular but you are using Angular for some reason, another thing I notice you never passed the code to your function which means
this
ng-click="ButtonCountry ()"
//should be this
ng-click="ButtonCountry('thecode')"
and the data you are posting isn't similar to the parameter name,
you have to change this
post("/Country/Angular", { CodH: Cod })
//to this
post("/Country/CalificacionesAngular", { codCountry: Cod })
there might be some more issues, these are the one I could see so far, please debug and provide more details about the error you are getting.
A good example you can check as well is this and this, and I suggest reading about Directives, Binding, scope, and Events

Adding custom right click menu to the nodes of treeview in MVC

This is my helper for generating a treeview.
Using this i am able to generate the treeview in the mvc5.
#helper GetTreeView(List<MvcTreeview.Models.Category> siteMenu, int parentID)
{
foreach (var i in siteMenu.Where(a => a.ParentID.Equals(parentID)))
{
<li>
#{var submenu = siteMenu.Where(a => a.ParentID.Equals(i.ID)).Count();}
#if (submenu > 0)
{
<span class="collapse collapsible"> </span>
}
else
{
<span style="width:15px; display:inline-block"> </span>
}
<span id="Category">
#i.CategoryName
#*oncontextmenu="return false"*#
</span>
#if (submenu > 0)
{
<ul>
#Treeview.GetTreeView(siteMenu, i.ID)
#* Recursive Call for Populate Sub items here*#
</ul>
}
</li>
}
}
This is my View for displaying
#model List<MvcTreeview.Models.Category>
#{
ViewBag.Title = "Simple";
}
<div class="gridbox gridleft">
<div class="left">
<div style="padding:10px; background-color:#FAFAFA">
<div class="treeview">
#if (Model != null && Model.Count() > 0)
{
<ul>
#Treeview.GetTreeView(Model, Model.FirstOrDefault().ParentID)
</ul>
}
</div>
</div>
</div>
</div>
<div id="onSuccess">
</div>
#* Here We need some Jquery code for make this treeview collapsible *#
#section Scripts{
<script type="text/javascript">
$(document).ready(function () {
$(".treeview li>ul").css('display', 'none'); // Hide all 2-level ul
$(".collapsible").click(function (e) {
e.preventDefault();
$(this).toggleClass("collapse expand");
$(this).closest('li').children('ul').slideToggle();
});
});
function PassingFunction(clicked_id) {
url = '#Url.Action("Details", "TestDetails")';
$.ajax({
url: url,
type: 'GET',
data: { 'id': clicked_id },
success: function (returnData) {
$("#onSuccess").html(returnData);
console.log(returnData);
},
error: {
}
});
}
</script>
}
Now i want to add the custom functionalities to the nodes of the treeview
Add
Delete
Edit
How can i do that?
There is a lot of JQuery Context Menu options on this link.
I have just picked the most forked of them, jQuery contextMenu.
I created a JSFeed fork in an example of treeview using UL/LI and created this JSFiddle with the Context-Menu to help you:
http://jsfiddle.net/mqueirozcorreia/0h82qto6/
Explaining the code:
I have added the externals resources:
http://swisnl.github.io/jQuery-contextMenu/dist/jquery.contextMenu.min.css
https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js
http://swisnl.github.io/jQuery-contextMenu/dist/jquery.contextMenu.min.js
All the magic goes in the javascript code, configuring the context-menu.
The selector property will put the context menu in every element of type <span> and having class attribute with value "contextMenuItem":
selector: 'span.contextMenuItem',
When the user clicks the callback function below runs. In this example, it alerts/logs what key was selected and the id attribute value.
callback: function(key, options) {
var m = "clicked: " + key + " on element of id " + options.$trigger.attr("id");
window.console && console.log(m) || alert(m);
},

How to set navbar item as active when user selects it?

I am a new ASP.NET Web Forms developer and trying to use Twitter Bootstrap with the Master Page. I am struggling with setting navbar item as active when user selects it. I created my simple master page by following this tutorial about how to use Twitter Bootstrap with ASP.NET.
Here's the code of my master page:
<%# Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="container">
<div class="row-fluid">
<div class="span12">
<div class="page-header">
<h1>Hello... My First Website with Twitter Bootstrap</h1>
</div>
</div>
</div>
<div class="row-fluid">
<div class="span3">
<ul class="nav nav-list">
<li class="nav-header">Navigation</li>
<li class="active">ASP.NET</li>
<li>Java</li>
<li>VB.Net</li>
<li>C#</li>
</ul>
</div>
<div class="span9">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
Then, I added this script to the Head in order to fix issue with the menu:
<script type="text/javascript">
$(document).ready(function () {
var url = window.location.pathname;
var substr = url.split('/');
var urlaspx = substr[substr.length - 1];
$('.nav').find('.active').removeClass('active');
$('.nav li a').each(function () {
if (this.href.indexOf(urlaspx) >= 0) {
$(this).parent().addClass('active');
}
});
});
</script>
However, nothing has been changed. When I selected any item from the navigation bar, the active class has not been added to the new selected item and I don't know why. Could you please help me in fixing this issue.?
Use this:
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li class="active">Default</li>
<li>Clients</li>
<li>Display</li>
</ul>
</div>
</div>
</div>
$(document).ready(function () {
var url = window.location;
$('.navbar .nav').find('.active').removeClass('active');
$('.navbar .nav li a').each(function () {
if (this.href == url) {
$(this).parent().addClass('active');
}
});
});
Example: http://jsfiddle.net/yUdZx/3/
And, in the "href" use "Page.ResolveUrl"
Clients
It's better...
Actually Reynaldo, almost had it...
At least for me, this works pretty good, on activing the current option and deactiving the previous one, based on his example.
$(document).ready(function() {
var url = window.location;
$('ul.nav li a').each(function () {
if (this.href == url) {
$("ul.nav li").each(function () {
if ($(this).hasClass("active")) {
$(this).removeClass("active");
}
});
$(this).parent().addClass('active');
}
});
});
For those as myself that prefer server-side implementations, transform your li tags of interest to runat="server" on the Master.Page file. The code in question will look something similar to this:
<div class="collapse navbar-collapse" id="menu">
<ul class="nav navbar-nav ml-auto">
<li class="nav-item" runat="server" id="tabHome" >
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item" runat="server" id="tabContact">
<a class="nav-link" href="/Contact">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link" runat="server">Hello, <asp:LoginName runat="server" />
</a>
</li>
</ul>
</div>
Then in the code behind of the Master page - Site.Master.vb or Site.Master.cs, depending on the language used - add the following in the Page Load event:
VB.Net implementation:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim thisURL As String = Request.Url.Segments(Request.Url.Segments.Count - 1)
Select Case thisURL
Case "Default", "default.aspx"
tabContact.Attributes.Remove("active")
tabHome.Attributes.Add("class", "active")
Case "Contact"
tabHome.Attributes.Remove("active")
tabContact.Attributes.Add("class", "active")
End Select
End Sub
C# implementation:
Protected void Page_Load(Object sender, EventArgs e)
{
string thisURL = Request.Url.Segments[Request.Url.Segments.Length - 1];
switch (thisURL)
{
Case "Default":
Case "default.aspx":
{
tabContact.Attributes.Remove("active");
tabHome.Attributes.Add("class", "active");
break;
}
Case "Contact" :
{
tabHome.Attributes.Remove("active");
tabContact.Attributes.Add("class", "active");
break;
}
}
}
Since is "Default.aspx" the page that is supposed to be opened initially, the "Home" menu item will be highlighted as soon the user enters the website. An example is displayed below:
For the sake of simplicity, only two navbar items were used in the example, but the same logic could be implemented if more are required.
I hope can be of help.
I've placed this in each one of my content pages, changing the id of the nav item for each page (this uses JQuery selectors). So for this to work for you you'll need to give your list items an Id. I don't add the "active" class to the master page because all we need to do is highlight the appropriate one when the content loads.
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$("[id$=yourNavItemId]").addClass("active");
});
</script>
Note: if you're using ASP.NET controls instead of list items inside of your nav bar, they might be getting prefixed at runtime causing your javascript not to find the Id you think you're looking for.
following code works if I have subpages:
$(document).ready(function () {
$('.navbar .nav').find('.active').removeClass('active');
var url = window.location.toString();
var u = url.substring(0, url.lastIndexOf("/")).toString();
$('.navbar .nav li a').each(function () {
var hr = this.href.substring(0, this.href.lastIndexOf('/')).toString();
if ((u == hr) || (u.indexOf(hr) > -1))
{
$(this).parent().addClass('active');
return false;
}
});
// Deactivation to manually add items you have with href = "#" example:
$('#liSalir').removeClass('active');
});
If you are using navigation bar with dropdown-menu then put below script at end of your master page(before body closing tag):
<script type="text/javascript">
$(document).ready(function () {
var url = window.location;
$('ul.nav li a').each(function () {
if (this.href == url) {
$("ul.nav li").each(function () {
if ($(this).hasClass("active")) {
$(this).removeClass("active");
}
});
$(this).parent().parent().parent().addClass('active');
}
});
});
</script>
This completely worked for me.
I know this post is old but use
$(document).ready(function () {
var url = window.location;
$('ul.nav li a').each(function () {
if (this.href == url) {
$("ul.nav li").each(function () {
if ($(this).hasClass("active")) {
$(this).removeClass("active");
}
});
$(this).parents().addClass('active');
}
});
});
Since you also wants to active the all the parents.
var windowUrl = window.location.href.toLowerCase();
//var windowUrl = window.location.href.toLowerCase().split('.')[0];
setTimeout(function () {
var windowUrl = window.location.href.toLowerCase();
$('#nav li').removeClass('active');
$('#nav li').each(function (index) {
pageUrl = $(this).find('a').attr('href');
if (windowUrl.indexOf(pageUrl) > -1) {
$(this).addClass('active');
}
});
}, 10);
I have created a sample which full fill your requirement you need to modify the code according to your need.
Use this jquery on master page
<script type="text/javascript">
$(function () {
$('[id*=submenu]').addClass('sub-menu open');
$('[id*=Master_Pages]').attr("aria-expanded", true);
$('.subMenus').click(function () {
localStorage.setItem('lastTab', $(this).attr('id'));
});
});
function pageLoad() {
var isActiveLink = false;
$.each($('.subMenus'), function () {
if ($(this).attr('id') == localStorage.getItem('lastTab')) {
$(this).closest('li').addClass('active');
localStorage.removeItem('lastTab');
isActiveLink = true;
}
else {
$(this).closest('li').removeClass('active');
}
});
if (!isActiveLink) {
$('[id*=Master_Designation]').closest('li').addClass('active');
}
}
</script>
Some helpful article for .Net guys
https://gist.github.com/josephwambura/ef97b44c309226301847d3e09e0e2562?permalink_comment_id=4381643#gistcomment-4381643

I'm using Ajax to populate my web page, but the populated HTML isn't working

I'm using Ajax to dynamically populate a DIV. I have each page content stored in XML files as CDATA. When a user clicks on a link from the navigation bar, the Ajax loads the XML for that particular page, parses it, and populates the DIV with it's content.
Everything is working GREAT, except for one thing. I have a jQuery modal popup whose markup is loaded from that page's XML file. The .js and .css files from the jQuery plugin are all loaded, and when this is HARD CODED (i.e., not loaded from XML), it works fine. But when it's loaded from the XML, the modal doesn't work.
When the page is loaded from the XML file- What the page is supposed to do is load the HTML from the XML file, which it does, and there's a hyperlink that when clicked, it's supposed to create the modal popup window. Instead, clicking on the link does NOT fire up the modal popup window.
When the page is hard coded- it does everything it's supposed to do.
A live example is at:
http://mikemarks.net/clientSites/tabras/
Click on "The Band", and at the bottom you'll see the hyperlink called "Demo". Clicking on that should bring up a modal popup window, but instead as you can see it just takes you to the top of the page.
Below is my markup (notice the div id="copy", which is the placeholder for my HTML content that's loaded from the XML file), my Ajax JavaScript code, and my XML file (which is shown as the markup that's loaded into the div id="copy").
<div id="leftTwoThirdsColumn">
<div id="menu">
<ul class="menu">
<li style="width:65px;"><a id="default" href="#" onclick="makeRequest('xml/default.xml');"><span>Home</span></a></li>
<li style="width:65px;"><a id="lyrics" href="#" onclick="makeRequest('xml/lyrics.xml');"><span>Lyrics</span></a></li>
<li style="width:110px;"><a id="merch" href="#" onclick="makeRequest('xml/merch.xml');"><span>Merchandise</span></a></li>
<li style="width:93px;"><a id="bio" href="#" onclick="makeRequest('xml/bio.xml');"><span>The Band</span></a></li>
<li style="width:80px;"><a id="contact" href="#" onclick="makeRequest('xml/contact.xml');"><span>Contact</span></a></li>
<li style="width:150px;" class="last"><a id="friends" href="#" onclick="makeRequest('xml/friends.xml');"><span>Friends of Tabräs</span></a></li>
</ul>
</div>
<br /><br />
<div id="copy">
</div>
</div>
function makeRequest(url)
{
if(window.XMLHttpRequest)
{
request = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
request = new ActiveXObject("MSXML2.XMLHTTP");
}
sendRequest(url);
}
function sendRequest(url)
{
request.onreadystatechange = onResponse;
request.open("GET", url, true);
request.send(null);
}
function checkReadyState(obj)
{
if(obj.readyState == 0) { document.getElementById('copy').innerHTML = "Sending Request..."; }
if(obj.readyState == 1) { document.getElementById('copy').innerHTML = "Loading Response..."; }
if(obj.readyState == 2) { document.getElementById('copy').innerHTML = "Response Loaded..."; }
if(obj.readyState == 3) { document.getElementById('copy').innerHTML = "Response Ready..."; }
if(obj.readyState == 4)
{
if(obj.status == 200)
{
return true;
}
else if(obj.status == 404)
{
// Add a custom message or redirect the user to another page
document.getElementById('copy').innerHTML = "File not found";
}
else
{
document.getElementById('copy').innerHTML = "There was a problem retrieving the XML.";
}
}
}
function onResponse()
{
if(checkReadyState(request)) {
var response = request.responseXML.documentElement;
var root = new Array();
root = response.getElementsByTagName('');
//alert("Total Number of HTML Elements Found: " + response.getElementsByTagName("").length);
var html = '';
for (var i = 0; i < root.length; i++) {
var tagName = response.getElementsByTagName("").item(i).nodeName;
var tagObj = response.getElementsByTagName("").item(i);
html += tagObj.firstChild.nodeValue;
}
document.getElementById('copy').innerHTML = html;
}
}
<div style="padding-top:5px; margin-left:auto; margin-right:auto; text-align:center;">
<img src="images/ShawnBioActive.png" />
<img src="images/JasonBioActive.png" />
<img src="images/WillBioActive.png" />
<img src="images/RasoulBioActive.png" />
<img src="images/bioStrip.png" />
<div id=&apos;basic-modal&apos;><h3>Basic Modal Dialog</h3><p>A basic modal dialog with minimal styling and no additional options. There are a few CSS attributes set internally by SimpleModal, however, SimpleModal relies mostly on style options and/or external CSS for the look and feel.</p><input type=&apos;button&apos; name=&apos;basic&apos; value=&apos;Demo&apos; class=&apos;basic&apos;/> or <a href=&apos;#&apos; class=&apos;basic&apos;>Demo</a></div><script type="text/javascript" src="../js/modal/jquery.simplemodal.js"></script><script type="text/javascript" src="../js/modal/basic.js"></script><link type="text/css" href="../css/modal/demo.css" rel="stylesheet" media="screen" /><link type="text/css" href="../css/modal/basic.css" rel="stylesheet" media="screen" /><script type=&apos;text/javascript&apos;>jQuery().ready(function () {$(&apos;#basic-modal-content&apos;).modal();});</script>
<div id="basic-modal-content"><h3>Basic Modal Dialog</h3></div><div style=&apos;display:none&apos;><img src=&apos;images/modal/basic/x.png&apos; alt=&apos;&apos; /></div></test2>
</div>
It seems that your webpage lacks of jquery.simplemodal.js and basic.js and the css associated ( for example, for the display:none; on your basic-modal-content )
That's why you don't have any modal on load.
Plus, your link or button doesn't have any event handler (for example, $('.basic').click(...);)
That's why you don't have any other action than the anchor.
To remove the anchor action, I recommand to use event.preventDefault
Three problems:
It is moving you to the top because you have a href="#" change it to href="javascript:void(0)"
http://mikemarks.net/clientSites/js/modal/jquery.simplemodal.js returns 404. Check location
http://mikemarks.net/clientSites/js/modal/basic.js returns 404. Check location

How to return Nested PartialViews (including their javascript) from an AJAX call in ASP.Net MVC

I have created a treeview of Categories using nested partial views:
my Index page (that displays the treeview):
<div>
Category Menu:
<input type="button" value="1" name='selectCat_btn' />
<input type="button" value="2" name='selectCat_btn' />
</div>
<!-- Treeview -->
<% Html.RenderPartial("ItemCats_UL", Model); %>
<div id="CatSelectorOutput">
</div>
ItemCats_UL:
<div>
<ul id="catsTree">
<% Html.RenderPartial("ItemCats_LI", Model); %>
</ul>
</div>
<script type="text/javascript" >
$(document).ready(function() {
$("#catsTree").treeview();
</script>
ItemCats_LI:
<%foreach (ItemCategory itemCat in Model)
{ %>
<li>
<%= itemCat.Name %>
<%if (itemCat.Children != null && itemCat.Children.Count() > 0)
{ %>
<ul>
<% Html.RenderPartial("ItemCats_LI", itemCat.Children); %>
</ul>
<%} %>
</li>
<%} %>
Now this treeview works perfectly when I return the basic View("Index", Model) from my controllers Index action on page load.
The trouble comes when I want to change the Categories Model displayed in my Treeview (the nested partialViews) from an AJAX call...
For example: I click one the 'Cats2' button and the page should display Categories with ParentID of 2 in the Treeview. I attempted this by returning a JsonResult of the html of the ItemCats_UL PartialView (using a RenderPartialToString method found here) from my Controller Action. As some of you might know Javascript won't run in your partial view when you use an AJAX form to return a PartialViewResult, and I need Javascript in my Treeview which is why I'm using the RenderPartialToString.
The category select button click handler:
<script type="text/javascript">
$("[name='selectCat_btn']").click(function() {
var CID = $(this).attr('value');
$.ajax({
type: "POST",
url: "SelectCat",
dataType: "json",
data: { "CID": CID },
success: function(result) { $("#CatSelectorOutput").html(result.output); }
});
return false;
});
</script>
My Controller Action:
[AcceptVerbs(HttpVerbs.Post)]
[UrlRoute(Name = "SelectCat", Path = "selectCat")]
public ActionResult SelectCat(int CID)
{
IQueryable<ItemCategory> cats;
cats = ItemRepo.GetItemCats().WithCID(CID);
JsonResult result = null;
result = new JsonResult
{
Data = new
{
success = true,
output =
Helpers.RenderHelper
.RenderPartialToString("~/Views/Admin/AdminItemCatsUL.ascx",
cats)
}
};
return result;
}
The result:
The ItemCats_UL partialView displays! BUT the nested PartialViews (ItemCats_LI) don't!
Error I receive when I step through the markup in the ItemCats_UL.ascx and hover over the 'Html' part of the following code:
<ul id="catsTree">
<% Html.RenderPartial("ItemCats_LI", Model); %>
</ul>
Value cannot be null.
Parameter name: viewContext
Html = 'Html' threw an exception of type 'System.ArgumentNullException'
I'm wondering if there's a clever guy out there who can extend the RenderPartialToString method to include nested partialviews? Or am I missing something simple?
You need to hook the newly returned HTML / JavaScript back into the DOM upon loading it.
I'm sure there are lots of ways to do this, but I found a nice jQuery add-on called LiveQuery (link)
that helps me do it.
To make it work in your case, you'd set up a jQuery document.ready function in the parent page that looks something like this:
$("#catsTree").livequery(function () { this.treeview(); }, function () { /* code to destroy the treeview here */ });

Resources