1

我正在尝试通过 ajax 加载数据的 Jquery UI 选项卡。链接以编程方式生成。

string LinkID = "";

<ul>
 @foreach (MyItem item in Model.ItemList)
 {
   <li>
    LinkID = "subcat" + ViewBag.F_ID + "-tabs-item" + item.ID + "-link";
    @Html.ActionLink( item.Name,           //Link Text
                     "GetItem",            //Action Name
                     "Items",              //Controller Name
                      //Route Values
                      new { C_ID = ViewBag.C_ID, D_ID = ViewBag.D_ID, E_ID = ViewBag.E_ID, F_ID = ViewBag.F_ID, G_ID = ViewBag.G_ID, Item_ID = item.ID }, 
                      //HTML Attributes
                      new { id = LinkID, @class = "ItemLoadViaAjax", title = item.Name })
   </li>   
  }
 </ul>   

生成的锚元素:

  <a class="ItemLoadViaAjax" 
     href="#Cadbury_Eclairs" 
     id="subcat11-tabs-item9-link" 
     title="Cadbury Eclairs">
     Cadbury Eclairs
  </a>

href值与 的值相同title,而不是从 ActionLink 生成的 URL。

知道为什么会这样吗?

4

2 回答 2

0

Try below. think you are passing values for routevalues parameter

@Html.ActionLink(linkText: item.Name, actionName: "GetItem", 
                  controllerName: "Items", 
                  RouteValues: new { C_ID = ViewBag.C_ID, D_ID = ViewBag.D_ID, E_ID =  ViewBag.E_ID, F_ID = ViewBag.F_ID, G_ID = ViewBag.G_ID, Item_ID = item.ID }
                  htmlAttributes: new { id = LinkID, @class = "ItemLoadViaAjax", title = item.Name },
routeValues: null)

Working on ASPX Views.

<a class="ItemLoadViaAjax" href="/TRS/ControllerName/ActionName.aspx?C_ID=ViewBag.C_ID&amp;D_ID=ViewBag.D_ID&amp;E_ID=ViewBag.E_ID&amp;F_ID=ViewBag.F_ID&amp;G_ID=ViewBag.G_ID&amp;Item_ID=item.ID" id="LinkID" title="item.Name">LinkText</a>
于 2012-06-20T12:35:54.907 回答
0

我不知道它发生的原因,但我Html.ActionLink用一个将值设置为 div 的 ID 并使用“onclick”函数调用另一个 Javascript 函数来执行 ajax 发布的<a href..>语句替换。href

于 2012-06-22T08:59:12.887 回答