Hide/Disable submit button from controller
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="开发者_如何学JAVApdf" />
</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>
精彩评论