Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass the ParentNode Value from the JQuery TreeView to the Controller method on ASP.NET MVC Page?
    primarykey
    data
    text
    <p>I have an ASP.NET MVC page that has left Menu Navigation that is built dynamically using JQuery Treeview Control.</p> <p>This Treeview has the list of <strong>ProductNames</strong> as the <strong>Parent Node</strong>(For Example: 10 Products). Each of these Products have a <strong>ChildNode</strong> as <strong>DocTypeName</strong>(For Example: 3 DocTypeNames).</p> <p>Here When the user clicks on ParentNode, it expands and shows DocTypeNames. When the User Clicks on DocTypeName, it loads the partialView by calling the controller ActionResult <strong>DocumentDetails</strong> through Ajaxy way.</p> <p>From the below code I am able to read the DocTypeName that is clicked. But I am not able to read the ProductName. It says "Undefined".</p> <p>Anyone has any idea how to pass the Parent ProductName to the controller?</p> <p><strong>NavigationProducts.ascx Page:</strong></p> <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;MedInfoDS.Controllers.ProductViewModel&gt;" %&gt; &lt;script type="text/javascript"&gt; $(document).ready(function () { $(".docId").click(function () { alert("DocTypeName: " + this.id); alert("ProductName: " + this.ProductName); //Error throwing here "Undefined" $("#docDetails").load('&lt;%= Url.Action("DocumentDetails") %&gt;', { ProductName: "darbepoetin alfa", DocTypeName: this.id }, function (responseText, status) { }); return false; }); }); </code></pre> <p> </p> <pre><code>&lt;div id="treecontrol"&gt; &lt;a title="Collapse the entire tree below" href="#"&gt;Collapse All&lt;/a&gt; | &lt;a title="Expand the entire tree below" href="#"&gt;Expand All&lt;/a&gt; | &lt;a title="Toggle the tree below, opening closed branches, closing open branches" href="#"&gt;Toggle All&lt;/a&gt; </code></pre> <p></p> <pre><code>&lt;div id="divByProduct"&gt; &lt;ul id="red" class="treeview-red"&gt; &lt;% foreach (var item in Model.Products) { %&gt; &lt;li&gt;&lt;span&gt; &lt;%=item.Name%&gt;&lt;/span&gt; &lt;ul&gt; &lt;%foreach (var item1 in Model.DocTypes) { %&gt; &lt;li&gt;&lt;span&gt; &lt;%= Html.ActionLink(item1.DocTypeName, "Products", new { ProductName = item.Name, DocTypeName = item1.DocTypeName })%&gt; &lt;br /&gt; &lt;a class="docId" href="#" id="&lt;%=item1.DocTypeName%&gt;"&gt;&lt;%= item1.DocTypeName%&gt;&lt;/a&gt; &lt;%= Html.Hidden("ProductName", item.Name)%&gt; &lt;/span&gt;&lt;/li&gt; &lt;% } %&gt; &lt;/ul&gt; &lt;/li&gt; &lt;% } %&gt; &lt;/ul&gt; </code></pre> <p></p> <p><strong>Controller Method:</strong></p> <pre><code>// Response to AJAXy call to populate details for given ProductName and DocType [HttpPost] public virtual ActionResult DocumentDetails(string ProductName, string DocTypeName) { var entities = new MIDSContainer(); if (ProductName == null) return View(); int ProductId = (entities.Products.FirstOrDefault(p =&gt; p.Name == ProductName)).ProductId; int DocTypeId = (entities.DocTypes.FirstOrDefault(d =&gt; d.DocTypeName == DocTypeName)).DocTypeId; var documents = (from d in entities.Documents.Where(p =&gt; p.ProductId == ProductId &amp;&amp; p.DocTypeId == DocTypeId &amp;&amp; p.AvailableForUse == true &amp;&amp; p.Status == "Approved") orderby (d.Description) select d).ToList(); return View(documents); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload