我如何知道使用request.form
的表單上的具體值? 我正在嘗試它,但沒有成功。我如何知道使用`request.form`的窗體上的具體值?
i want to check something like this
if (request.form.contains("text_check")) //But it doesn't work
{
go in;
}
else{
here we go;
}
我想知道AllKeys的具體數值,以及所有鍵的總數。
我如何知道使用request.form
的表單上的具體值? 我正在嘗試它,但沒有成功。我如何知道使用`request.form`的窗體上的具體值?
i want to check something like this
if (request.form.contains("text_check")) //But it doesn't work
{
go in;
}
else{
here we go;
}
我想知道AllKeys的具體數值,以及所有鍵的總數。
如果你想檢查是否有某些關鍵的Request.Form
集合中存在,你可以這樣做是這樣的:
if(Request.Form.AllKeys.Any(k => k == "text_check")) { ... }
,並隨後得到它的價值:
if(Request.Form.AllKeys.Any(k => k == "text_check"))
{
var textCheckValue = Request.Form["text_check"];
}
要獲得總然後鍵數:
var count = Request.Form.AllKeys.Count();
如果您使用服務器端控件,可以使用Request.Form.Contains(text_check.UniqueId)
確保表單在回發期間具有該值。
要檢查是否有鍵的形式數據時,可以將該值只是比較空:
if (Request.Form["text_check"] != null) {
如果密鑰存在,你總能得到一個字符串值回,即使值爲空。
如果你想檢查是否有一個非空值,可以使用String.IsNullOrEmpty
方法:
if (!String.IsNullOrEmpty(Request.Form["text_check"])) {