【发布时间】:2015-01-03 18:18:10
【问题描述】:
我的目标是有一个默认值 Block 的按钮,当用户点击它时,它会将文本更改为 Unblock 并且在页面刷新后按钮的文本必须保持不变,如果文本被更改解锁然后刷新后它必须保持解锁状态。
到目前为止我尝试过的是这样的:
查看按钮代码:
input type="submit" value="@ViewBag.SubmitValue" id="Block" style="color: white;
background-color: darkred; border-bottom-left-radius: 2px; border-bottom-right-radius: 2px;
border-top-left-radius: 2px; border-top-right-radius: 2px; padding: 4px 4px;
border: none; padding-bottom:2px "
控制器动作结果
public ActionResult Block(int Id, Block block, string userAction)
{
if(userAction == "Block")
{
ViewBag.SubmitValue = "Block";
}
if (userAction == "Unblock")
{
ViewBag.SubmitValue = "Unblock";
}
.....
}
我在 ActionResult 中的这个传递字符串 userAction 中遇到问题,userAction 的值在方法中作为 Null 传递,所以按钮的文本没有改变,它在按钮上显示“提交”
请帮忙
【问题讨论】:
标签: asp.net-mvc button viewbag actionresult