ساخت قالبهای نمایشی و ادیتور دکمه سه وضعیتی سازگار با Twitter bootstrap در ASP.NET MVC
نویسنده: وحید نصیری
تاریخ: ۱۳۹۲/۰۴/۰۴ ۸:۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
<div class="btn-group" data-toggle="buttons-radio">
<button class="btn" type="button">بلی</button>
<button class="btn" type="button">خیر</button>
</div>using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace Mvc4TwitterBootStrapTest.Models
{
public class User
{
public int Id { set; get; }
[DisplayName("نام")]
[Required(ErrorMessage="لطفا نام را تکمیل کنید")]
public string Name { set; get; }
[DisplayName("نام خانوادگی")]
[Required(ErrorMessage = "لطفا نام خانوادگی را تکمیل کنید")]
public string LastName { set; get; }
[DisplayName("فعال است؟")]
[UIHint("BootstrapBoolean")]
public bool? IsActive { set; get; }
}
}@model bool?
@{
var yesIsSelected = Model.HasValue && Model.Value ? "active" : null;
var noIsSelected = Model.HasValue && !Model.Value ? "active" : null;
var isIndeterminate = !Model.HasValue ? "active" : null;
var htmlField = ViewData.TemplateInfo.HtmlFieldPrefix;
}
@Html.HiddenFor(model => model)
<div class="btn-group" data-toggle="buttons-radio">
<button type="button" class="btn btn-info @yesIsSelected bool-@htmlField" onclick="$('#@htmlField').val(true);">
بلی</button>
<button type="button" class="btn btn-info @noIsSelected bool-@htmlField" onclick="$('#@htmlField').val(false);">
خیر</button>
@if (ViewData.ModelMetadata.IsNullableValueType)
{
<button type="button" class="btn btn-info @isIndeterminate bool-@htmlField" onclick="$('#@htmlField').val('');">
نامشخص</button>
}
</div>@model bool?
@if (Model.HasValue)
{
if (Model.Value)
{
<span class="label label-success">بلی</span>
}
else
{
<span class="label label-important">خیر</span>
}
}
else
{
<span class="label label-inverse">نامشخص</span>
}[UIHint("BootstrapBoolean")]
public bool? IsActive { set; get; } $(this).siblings().removeClass('active'); $(this).addClass('active');