@ Html.TextBox(" SomeID"," SomeValue",new {type =" Checkbox"}}) [英] @Html.TextBox("SomeID", "SomeValue" ,new { type = "Checkbox" })

查看:87
本文介绍了@ Html.TextBox(" SomeID"," SomeValue",new {type =" Checkbox"}})的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在视图页面上使用asp.net mvc 4中的文本框创建了一个复选框。



@ Html.TextBox(SomeID,SomeValue ,新{type =Checkbox})



现在基于某些条件,我想选中此复选框。



怎么可能呢?



我试过@ Html.TextBox(SomeID,SomeValue,new {type =Checkbox ,value =true})



但它不起作用。



谢谢。

解决方案

您应该将 AllowRating 属性设置为true,最好是在控制器或模型中。

和其他人一样输入,复选框的状态反映了属性的值。


使用javaScript / jquery你可以选中/取消选中复选框



< script type =   text / javascript> 
if // 这里检查你的条件)
{


#SomeID )。attr(' 选中');
}



< / script>





OR



 @ Html.TextBox(SomeID,someValue,new {type =Checkbox,@ checked = true} )


I have created a checkbox using textbox in asp.net mvc 4 on view page like this.

@Html.TextBox("SomeID", "SomeValue" ,new { type = "Checkbox" })

now based on some condition, I would like to check this checkbox.

How could it be possible?

I have tried @Html.TextBox("SomeID", "SomeValue" ,new { type = "Checkbox", value = "true" })

but it is not working.

Thank you.

解决方案

You should set the AllowRating property to true, preferably in the controller or model.
Like other inputs, the checkbox's state reflects the value of the property.


by using javaScript/jquery you can Check/Uncheck the checkBox

<script type="text/javascript">
    if (//Here Check your Condition)
    {


("#SomeID").attr('checked', true); }


</script>


OR

@Html.TextBox("SomeID", "someValue" ,new { type = "Checkbox",@checked=true })


这篇关于@ Html.TextBox(&quot; SomeID&quot;,&quot; SomeValue&quot;,new {type =&quot; Checkbox&quot;}})的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆