Asp.net mvc 我们可以从控制器上禁用按钮吗?-mvc
我的视图中有一些按钮 我想根据控制器的某些条件禁用一些按钮。Asp.net mvc 我们可以从控制器上禁用按钮吗?-mvc,asp.net-mvc,Asp.net Mvc,我的视图中有一些按钮 我想根据控制器的某些条件禁用一些按钮。 有什么方法可以做到这一点吗?在控制器中创建相同的标志,然后将其传递给视图。在视图内部,读取该标志,并根据需要禁用按钮。在控制器中创建相同的标志,然后将其传递给视图。查看内部视图,读取该标志,并根据需要禁用按钮。型号: public class MyModel { public bool SomeProperty { get; set; } public bool AnotherProperty { get; set; }
有什么方法可以做到这一点吗?在控制器中创建相同的标志,然后将其传递给视图。在视图内部,读取该标志,并根据需要禁用按钮。在控制器中创建相同的标志,然后将其传递给视图。查看内部视图,读取该标志,并根据需要禁用按钮。型号:
public class MyModel {
public bool SomeProperty { get; set; }
public bool AnotherProperty { get; set; }
}
行动:
public ViewResult Index() {
//strongly typed example
var model = new MyModel {
SomeProperty = true,
AnotherProperty = false
}
ViewData["Something"] = true; //view data example
return View(model);
}
视图:
some按钮
另一个按钮
某物
型号:
public class MyModel {
public bool SomeProperty { get; set; }
public bool AnotherProperty { get; set; }
}
行动:
public ViewResult Index() {
//strongly typed example
var model = new MyModel {
SomeProperty = true,
AnotherProperty = false
}
ViewData["Something"] = true; //view data example
return View(model);
}
视图:
some按钮
另一个按钮
某物
这篇文章很旧,但它在mvc3 c上工作,并且非常有用:
<button @Html.Raw(Model.SomeProperty ? "disabled=\"disabled\"" : "") >a button</button>
a按钮
这篇文章很旧,但它在mvc3 c上工作,并且非常有用:
<button @Html.Raw(Model.SomeProperty ? "disabled=\"disabled\"" : "") >a button</button>
a按钮
是的,确实有,但是如果你发布你的尝试和你遇到的问题,你就更有可能得到问题的答案。是的,确实有,但是,如果您发布您尝试过的内容以及您遇到的具体问题,您更有可能得到问题的答案。disabled属性的值应为“disabled”或空,而不是“true”/“false”。@David我们现在可以选择只放置“disabled”如果您想包含此项,则在元素上以及在HTML5上。禁用属性的值应为“disabled”或空,而不是“true”/“false”。@David如果您想包含此项,我们现在可以选择在元素上以及在HTML5上添加“disabled”。