【发布时间】:2014-10-26 00:54:13
【问题描述】:
我希望在 foreach 循环列表中包含指向 MyAction 的链接的 href 标签。
在 Edit.cshtml (http://localhost/mysite/Order/Edit/4) foreach 循环(淘汰赛)中,每个项目都有一个 href:
<a href="#" data-bind="click: $parent.EditForStore">Eddit</a>
方法在 ViewModel.js 中实现:
self.EditForStore = function (item) {
console.log(item.IdStore());
var idStore = item.IdStore();
//var urlMeta = '@Url.Action("MyAction", "MyController", new { pStoreId = ' + idStore.toString() + ' })';
var urlMeta = '@Url.Action("MyAction", "MyController", new { pStoreId = 4 })';
//var myURL = '@Url.Action("MyAction", "MyController")';
window.location.href = urlMeta;
};
我无法重定向到 MyAction。 当我设置 location.href 时,它会重定向到 http 地址:
http://localhost/mysite/Order/Edit/4/MyAction/MyController?pStoreId=4
我无法更改 location.href,我只能将文本附加到我当前的地址。
【问题讨论】:
-
你能在设置window.location之前注销
urlMeta里面的内容吗? -
在 urlMeta 中是 localhost/mysite/MyAction/MyController?pStoreId=4,当我设置 location.href 时,它会将我重定向到 localhost/mysite/Order/Edit/4/http://localhost/mysite/…
-
您使用的是哪个浏览器?如果您在不同的浏览器中尝试,您会得到相同的行为吗?
-
火狐,我会在其他浏览器上测试
-
@Url.Action 是 Razor 语法,需要在 cshtml 文件中