3

这就是我想要做 我的看法 的我有一排有一个打开按钮的项目,该按钮应该打开一个对话框,其中包含该项目,但我无法正确发布网址。在将此图添加到此问题时,我看到了 stackoverflow 如何弹出一个对话框,而这正是我需要做的。我的问题是我需要 url/controller/action?id= (id being passed in)但我得到的 url 是/controller/action?/7或者如果我重写操作我得到/controller/action?/7如何摆脱斜线或正确发布它?

行动链接

       @Html.ActionLink("Open", "AddItems", new { id = item.ID }, new { @id =
      "Itemdialog" })

jQuery

  $('#dialog').dialog({
    autoOpen: false,
    width: 400,
    resizable: false,
    modal: true
});

$('#Itemdialog').on("click", function () {
    var url =  $(this).attr('href');
    $('#dialog').load(url, function () {
        $(this).dialog('open');
    });

    return false; 
});

控制器:

   public ActionResult AddItems(int id)
    {
        var TradeItem = from i in db.Items
                        where i.ID == id
                        select i;
        var results = TItem;


        return PartialView("_OpenItem", results); //need to open in dialog

    }

看法

    @model IEnumerable<Item>

<table>
  <tr>
    <th>
         @Html.DisplayNameFor(model => model.ID)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.user_id)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.item_name)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.item_description)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.item_code)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.dateAdded)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.catId)
    </th>
    <th></th>
</tr>

@foreach (var item in Model) {

<tr>
    <td>
        @Html.DisplayFor(modelItem => item.ID)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.user_id)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.item_name)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.item_description)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.item_code)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.dateAdded)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.catId)
    </td>

</tr>
}

  </table>
   @Html.ActionLink(send to db )
4

1 回答 1

1

您可以保留routeValues空白,只需将查询字符串附加到末尾:

<a id="Itemdialog" href='@Url.Action("AddItems")?id=@item.ID'>Open</a>

我认为这是设置查询字符串的一种更直接的方法——使用routeValues意味着您要基于路由定义构造 URL。

于 2013-08-19T22:11:38.557 回答