我是MVC的新手,并且尝试从最近7个小时将值从viewBag传递到MVC 5中的javascript函数。 我有一个字符串变量
file = open("somefile.txt", "w")
subprocess.run(["df","-h"], stdout = file)
os.system("gnome-terminal -e 'gedit somefile.txt' ")
我将它传递给查看并将其存储为隐藏元素
ViewBag.c1 = "0.30"
然后我想在后面的js函数
中访问这个隐藏元素的值@Html.Hidden("Superman", (string)ViewBag.c1)
答案 0 :(得分:1)
@Html.Hidden("Superman", (string)ViewBag.c1)
function getValue1() {
return parseFloat($("#Superman").val());
}
//or
function getValue1() {
return parseFloat(document.getElementById("Superman").value);
}
答案 1 :(得分:1)
var c1Value = "@Html.Raw(ViewBag.c1)";
function getValue1() {
return parseFloat(document.getElementById(c1Value).value);
}
答案 2 :(得分:0)
您可以将视图包值存储在JavaScript变量中,如下所示。
import numpy as np
import pandas as pd
result = pd.DataFrame()
origDict = np.load("Hannah Lee.npy")
for item in range(len(origDict)):
newdict = {(k1, k2):v2 for k1,v1 in origDict[item].items() for k2,v2 in origDict[item][k1].items()}
df = pd.DataFrame([newdict[i] for i in sorted(newdict)],
index=pd.MultiIndex.from_tuples([i for i in sorted(newdict.keys())]))
print(df.bun)