隐藏/禁用从控制器提交按钮 [英] Hide/Disable submit button from controller
本文介绍了隐藏/禁用从控制器提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样可以隐藏控制器操作一个WebForm按钮?还是我做它在网络表单本身呢?
有是隐藏/禁用按钮的条件:
如果(StudentType!=高级)
{
隐藏按钮
}
显示按钮
查看:
<形式方法=邮报行动=/学生/调度/>
<标签=ID>学号:LT; /标签>
<输入类型=文本名称=ID值=/> < BR />< BR />
<输入类型=提交值=获取学生(XLS)NAME =XLS/> &安培; NBSP;&安培; NBSP
<输入类型=提交值=获取学生(PDF)NAME =PDF/>
< /表及GT;
控制器:
[HttpPost]
公众的ActionResult讯(PDF格式的字符串,字符串ID){
如果(!string.IsNullOrEmpty(PDF)){
// GetPdf提交按钮被点击
返回StudentPdf(ID);
}
// GetXls提交被点击按钮
返回StudentExcel(ID);
}
解决方案
您可以使用ViewData字典。
控制器:
如果(StudentType!=高级)
{
计算机[isHideButton] =真;
}
查看:
<形式方法=邮报行动=/学生/调度/>
<标签=ID>学号:LT; /标签>
<输入类型=文本名称=ID值=/> < BR />< BR />
<%布尔hideButton = FALSE;
bool.TryParse(计算机[isHideButton],hideButton)%GT;
<%,如果(!hideButton)
{%GT; <输入类型=提交值=获取学生(XLS)NAME =XLS/>
<%}%GT;
&安培; NBSP;&安培;&NBSP LT;输入类型=提交值=获取学生(PDF)NAME =PDF/>
< /表及GT;
How can I hide a webform button from controller action? or Do I do it in webform itself?
There is a condition to hide/disable the button:
if (StudentType != "Senior")
{
Hide Button
}
Display Button
View:
<form method="post" action="/Student/Dispatch/">
<label for="id">Student Number: </label>
<input type="text" name="id" value="" /> <br /><br />
<input type="submit" value="Get Student(xls)" name="xls" />  
<input type="submit" value="Get Student(pdf)" name="pdf" />
</form>
Controller:
[HttpPost]
public ActionResult Dispatch(string pdf, string id) {
if (!string.IsNullOrEmpty(pdf)) {
// GetPdf submit button was clicked
return StudentPdf(id);
}
// GetXls submit button was clicked
return StudentExcel(id);
}
解决方案
You can use ViewData dictionary .
Controller:
if (StudentType != "Senior")
{
ViewData["isHideButton"] =true;
}
View:
<form method="post" action="/Student/Dispatch/">
<label for="id">Student Number: </label>
<input type="text" name="id" value="" /> <br /><br />
<% bool hideButton= false;
bool.TryParse(ViewData["isHideButton"],hideButton)%>
<%if(!hideButton)
{%>
<input type="submit" value="Get Student(xls)" name="xls" />
<%}%>
  <input type="submit" value="Get Student(pdf)" name="pdf" />
</form>
这篇关于隐藏/禁用从控制器提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文