这是我试图从.js文件中获取的url,其中包含与淘汰相关的函数:
self.followAction = $.resolvePath("/People/Follow?uid=" + data.UserId);
这里People是控制器,Follow是动作方法,点击按钮,我想发送userId,所以我写了这个。
要从javascript中解析相对路径,我已编写此函数
// Fix for resolving relative paths from within js scripts
$.resolvePath = function(url)
{
var path = '@Request.ApplicationPath';
if (path != '/') return path + url;
return url;
};
但是,点击按钮,我收到此错误:HTTP错误404.0 - 未找到 和网址是:
localhost:44305/People/@Request.ApplicationPath/People/Follow?uid=8
请告诉我现在应该怎么做。提前罢了!
答案 0 :(得分:3)
Razor代码不在JS文件中解释,因此 //get the listview within the navigation drawer (0th child)
ListView menuList = (ListView) mNavigationView.getChildAt(0);
//get the header view (0th item in listview adapter)
final View headerView = menuList.getAdapter().getView(0, null, null);
if (headerView != null) {
headerView.setEnabled(false); //doesn't work, should
headerView.setFocusable(false); //doesn't work, should
headerView.setFocusableInTouchMode(false); //doesn't work, should
headerView.setClickable(false); //doesn't work, should
headerView.setOnClickListener(null); //WORKS! works to disallow clicking! is still focusable via keyboard
}
被读作文字字符串。您需要将代码放在将要执行的位置,以便JS可以读取它;也许作为View中元素的@Request.ApplicationPath
属性,如下所示:
data-*
<!-- in a layout view... -->
<body data-app-path="@Request.ApplicationPath">