我们可以动态改变的ASP.NET MVC页Ajaxy调用的网址是什么? [英] Can we dynamically change the URL with Ajaxy call on ASP.NET MVC page?

查看:195
本文介绍了我们可以动态改变的ASP.NET MVC页Ajaxy调用的网址是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,有一个叫做产品视图ASP.NET MVC应用程序。

本产品查​​看有正在使用NavMenuProducts.ascx管窥实施了左侧菜单导航。
此菜单是使用JQuery树视图,使其具有ProductNames作为父节点列表来实现,它是可扩展的(例如:10个产品)。
每个产品都有一个ChildNode作为DocTypeName,它是一个超链接(例如:3 DocTypeNames)。

当用户点击显示ChildNode超链接所有匹配的文档,并使用Ajaxy调用执行。这样,用户具有更好的用户界面体验。
但随着这个问题是永远的网址是静态的(例如:的http:// DocShare

但基于点击的节点,我要像 HTTP网址:// DocShare /产品/产品1 /信

我想知道如何使用Ajaxy调用,使这个动态的URL。

注意:如果我使用HTML.ActionLINK,然后我得到的动态URL。但是,这ActionLink的,而加载页面时,我们得到随机树形屏幕。为了避免这种闪烁的树的效果,我正在调用Ajax更好的UI体验。

任何的解决办法是AP preciated获取动态URL与Ajaxy通话。

下面是code:

NavigationProducts.ascx页:

 <%@控制语言=C#继承=System.Web.Mvc.ViewUserControl< MedInfoDS.Controllers.ProductViewModel>中%GT;
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){
    $(的docId)。点击(函数(){
        警报(DocTypeName:+ this.id);
        $(#docDetails)的负载('<%= Url.Action(DocumentDetails)%>',{产品名称:阿法达贝泊汀,DocTypeName:this.id},功能(responseText的,地位){        });        返回false;
    });
});

 < D​​IV ID =树形控件>
    <标题=折叠整个树下面的href =#>全部折叠< / A> | <标题=展开以下整个树
        HREF =#>全部展开< / A> | <标题=切换下面的树,开闭分支机构,关闭打开的分支
            HREF =#>切换所有< / A>
< / DIV>< D​​IV ID =divByProduct>
    < UL ID =红色级=树状红>
        <%的foreach(在Model.Products VAR项)
           {%GT;
        <立GT;<跨度>
            &所述;%= item.Name%GT;&下; /跨度>
            < UL>
                <%的foreach(在Model.DocTypes VAR ITEM1){%GT;                       <立GT;<跨度>
                            <%= Html.ActionLink(item1.DocTypeName,产品,新的产品名称{= item.Name,DocTypeName = item1.DocTypeName})%GT;
                            < BR />
                            &所述;类别=的docId的href =#ID =&下;%= item1.DocTypeName%gt;中与GT;&下;%= item1.DocTypeName%GT;&下; / A>
                            &所述;%= Html.Hidden(产品名称,item.Name)%GT;                       < / SPAN>< /李>
                <%}%GT;
            < / UL>
        < /李>
        <%}%GT;
    < / UL>
< / DIV>

控制器方法:

  //响应AJAXy调用来填充细节赋予产品名称和的DocType
        [HttpPost]
        公共虚拟的ActionResult DocumentDetails(串产品名称,字符串DocTypeName)
        {
            VAR实体=新MIDSContainer();
            如果(产品名称== NULL)返回查看();
            INT =产品编号(entities.Products.FirstOrDefault(P => p.Name ==产品名称))产品编号。
            INT DocTypeId =(entities.DocTypes.FirstOrDefault(D => d.DocTypeName == DocTypeName))。DocTypeId;
            VAR文件=(从entities.Documents.Where D组(P => p.ProductId ==&产品编号功放;&安培; p.DocTypeId == DocTypeId&放大器;&安培; p.AvailableForUse ==真放;&安培; p.Status ==已批准)排序依据(d.Description)选择D).ToList();
            返回查看(文件);
        }


解决方案

有一个pretty COM prehensive这里的解决方案:的 http://ajaxpatterns.org/Unique_URLs

I have an ASP.NET MVC application that has a view called Products.

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).

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: http://DocShare )

But based on the Node that is clicked, I want the url like http://DocShare/Products/Product1/Letter

I am wondering how to make this dynamic url using Ajaxy call.

NOTE: 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.

Any solution would be appreciated for getting dynamic url with Ajaxy call.

Here is the Code:

NavigationProducts.ascx Page:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MedInfoDS.Controllers.ProductViewModel>" %>


<script type="text/javascript">
$(document).ready(function () {
    $(".docId").click(function () {
        alert("DocTypeName: " + this.id);
        $("#docDetails").load('<%= Url.Action("DocumentDetails") %>', { ProductName: "darbepoetin alfa", DocTypeName: this.id }, function (responseText, status) {

        });

        return false;
    });
});

<div id="treecontrol">
    <a title="Collapse the entire tree below" href="#">Collapse All</a> | <a title="Expand the entire tree below"
        href="#">Expand All</a> | <a title="Toggle the tree below, opening closed branches, closing open branches"
            href="#">Toggle All</a>
</div>

<div id="divByProduct">
    <ul id="red" class="treeview-red">
        <% foreach (var item in Model.Products)
           { %>
        <li><span>
            <%=item.Name%></span>
            <ul>
                <%foreach (var item1 in Model.DocTypes) { %>

                       <li><span>
                            <%= Html.ActionLink(item1.DocTypeName, "Products", new { ProductName = item.Name, DocTypeName = item1.DocTypeName })%>
                            <br />
                            <a class="docId" href="#" id="<%=item1.DocTypeName%>"><%= item1.DocTypeName%></a>
                            <%= Html.Hidden("ProductName", item.Name)%>

                       </span></li>
                <% } %>
            </ul>
        </li>
        <% } %>
    </ul>
</div>

Controller Method:

// 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 => p.Name == ProductName)).ProductId;
            int DocTypeId = (entities.DocTypes.FirstOrDefault(d => d.DocTypeName == DocTypeName)).DocTypeId;
            var documents = (from d in entities.Documents.Where(p => p.ProductId == ProductId && p.DocTypeId == DocTypeId && p.AvailableForUse == true && p.Status == "Approved") orderby (d.Description) select d).ToList();
            return View(documents);
        }

解决方案

There's a pretty comprehensive solution here: http://ajaxpatterns.org/Unique_URLs

这篇关于我们可以动态改变的ASP.NET MVC页Ajaxy调用的网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆