Note that there are some explanatory texts on larger screens.

plurals
  1. POCan we dynamically change the URL with Ajaxy call on ASP.NET MVC page?
    primarykey
    data
    text
    <p>I have an ASP.NET MVC application that has a view called Products.</p> <p>This Products View has a Left Menu Navigation that is implemented using NavMenuProducts.ascx Partial View. This Menu is implemented using JQuery Treeview so that it has the list of ProductNames as the Parent Node and it is expandable(For Example: 10 Products). Each of these Products have a ChildNode as DocTypeName and it is a hyperlink(For Example: 3 DocTypeNames).</p> <p>When the user clicks ChildNode Hyperlink all the matching Documents are displayed and is implemented using Ajaxy call. So that the user has better UI experience. But the problem with this is the url always is static(Example: <a href="http://DocShare" rel="nofollow">http://DocShare</a> )</p> <p>But based on the Node that is clicked, I want the url like <a href="http://DocShare/Products/Product1/Letter" rel="nofollow">http://DocShare/Products/Product1/Letter</a></p> <p>I am wondering how to make this dynamic url using Ajaxy call.</p> <p><strong>NOTE:</strong> If I am using HTML.ActionLINK, then I am getting dynamic URL. But this ActionLink, while the Page is loading, we are getting random treeview screen. TO avoid that flickering tree effect, I am making Ajax call for better UI experience.</p> <p>Any solution would be appreciated for getting dynamic url with Ajaxy call.</p> <p>Here is the Code:</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); $("#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; &lt;/div&gt; &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; &lt;/div&gt; </code></pre> <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.
    1. This table or related slice is empty.
    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.
 

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