有人是否知道如何做到这一点简单的事:从angularjs一个隐藏的输入字段获取值?用Google搜索了很多没有真正成功的C#在服务器端写一个产品ID,我需要找回它把它传递给我angularjs JSON服务。
Does someone know how to do this simple thing : get a value from a hidden input field with angularjs ? Googled a lot without real success... C# in server side writes a product id, and I need to retrieve it to pass it to my angularjs json service.
感谢名单上百万次,如果你能回答!
Thanx a million times if you're able to answer!
这是我如何做到这一点:
This is how I do it:
@functions{
public string GetAntiForgeryToken()
{
string cookieToken, formToken;
AntiForgery.GetTokens(null, out cookieToken, out formToken);
return cookieToken + ":" + formToken;
}
}
<input id="antiForgeryToken" type="hidden" value="@GetAntiForgeryToken()" />
var antiForgeryToken = $("#antiForgeryToken").val();
的 修改的
EDIT
如果没有jQuery的:
Without jQuery:
var antiForgeryToken = document.getElementById("antiForgeryToken").value;
使用角$文件:
var antiForgeryToken = $document.find("#antiForgeryToken").val();