我想在用户单击按钮时禁用该按钮。我可以,但我觉得我的方法不太好。 我的方式:
我将ViewBag.IsSaveButtonDisabled
设置为true
并通过javascript检查此容器div,然后禁用了保存按钮。我知道,这是一个糟糕的解决方案。我想在服务器端控制提交按钮的禁用属性。
最佳实践是什么?
最佳答案
向您的ViewModel 添加新属性
型号
viewModel{
...
public string IsDisabled{ get; set; }
}
Controller
public ActionResult Index()
{
viewModel model = new viewModel { ... , IsDisabled = "disabled"};
return View(model);
}
在你看来
@model viewModel
<input type="submit" value="Kaydet" @Model.IsDisabled/>
关于asp.net-mvc - 当用户在 mvc 上单击提交按钮时禁用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14773447/