如何从控制器操作隐藏webform按钮?或者我是否在webform中做到了?
隐藏/禁用按钮有一个条件:
if (StudentType != "Senior")
{
Hide Button
}
Display Button
查看:
<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>
控制器:
[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);
}
答案 0 :(得分:3)
您可以使用ViewData字典。
控制器:
if (StudentType != "Senior")
{
ViewData["isHideButton"] =true;
}
查看:
<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>