【发布时间】:2013-04-14 11:31:21
【问题描述】:
我正在动态构建 URL 以传递给 jQuery 按钮单击事件处理程序。
URL 来自模态窗口定义:
<div class="modal hide fade in" id="modal-view-tenant-profile"
data-url="Tenants/ViewProfile">...</div>
id 来自一个按钮:
<button class="btn btn-primary btn-block show-modal"
data-id="@result.UserId">View profile</button>
在我的 JS 函数中,我抓取两条数据
var url = "Tenants/ViewProfile";
var id = $(this).attr('data-id');
然后像$.get(url + '/' + id, function (data))...这样构造URL
要正常工作,URL 应如下所示:
http://localhost:1840/Tenants/ViewProfile/2
但是因为这个控制器操作是从登录的 Lanlord 调用的,所以 URL 看起来像这样:
http://localhost:1840/Landlords/Tenants/ViewProfile/2
我知道我需要创建一个新路由来忽略 URL 的“房东”部分,当房东从租户控制器调用操作时,我该怎么做?
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing