我试图使用asp.net mvc 4 + jquery在特定路径中打开模态,继承代码:

Card.cshtml

<div class="btn-group">
    <button class="btn btn-primary openModal" data-path="/Client/Edit/@Model.ClientID">Editar</button>
    <button class="btn btn-primary openModal" data-path="/Client/Products/@Model.ClientID">Products</button>
</div>

然后在modal.js

$(document).on('click', '.openModal', function () {
    var path = $(this).attr("data-path");
    $("#modal").load(path, function () {
        $("#modal").modal();
    })
});

在ClientController中

public ActionResult Edit(long id = 0)
{
    Client client = db.Clients.Find(id);

    if (client == null)
    {
        return HttpNotFound();
    }

    return View(client);
}

public ActionResult Products(long clientID)
{
    return View(db.Products.Where(p => p.ClientID == clientID).ToList());
}

“编辑”操作有效,但“产品”操作不起作用(我设置断点并且未调用)。 怎么了?

===============>>#1 票数:1

问题是参数的名称

public ActionResult Products(long clientID)
{
    return View(db.Products.Where(p => p.ClientID == clientID).ToList());
}

从clientID更改为id并且正常工作。 这是因为默认路线是

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }

  ask by Rieth translate from so

未解决问题?本站智能推荐: