Skip to content

Instantly share code, notes, and snippets.

@mahmut-gundogdu
Last active July 13, 2017 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahmut-gundogdu/172401b0e75ad7dc7e6e6a1a022adb6d to your computer and use it in GitHub Desktop.
Save mahmut-gundogdu/172401b0e75ad7dc7e6e6a1a022adb6d to your computer and use it in GitHub Desktop.
Kullanıdığım tasarımda bool ve bazı int değerleri Evet Hayır  radiobutton ile belirli bir formatta göstermek istiyordum. göstermek istiyordum. ancak model dynamic olunca farklı cozum almam gerekti. Yazım: https://mahmutgundogdu.wordpress.com/2017/07/13/asp-net-mvc-editor-template-ile-custom-radio-button-group-yapimi
/// <summary>
/// Kaynak:https://stackoverflow.com/a/23383159/3928982
/// </summary>
public static MvcHtmlString RadioButtonFor<TModel, TValue>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TValue>> expression, object value, object htmlAttributes, bool checkedState)
{
var htmlAttributeDictionary = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
if (checkedState)
{
htmlAttributeDictionary.Add("checked", "checked");
}
return htmlHelper.RadioButtonFor(expression, value, htmlAttributeDictionary);
}
@model dynamic
@if (Model is bool || Model is bool?)
{
<div class="mt-radio-inline">
<label class="mt-radio mt-radio-outline">
Evet
@Html.RadioButtonFor(model => model, true, ViewData["HtmlAttributes"], (bool?)Model == true)
<span></span>
</label>
<label class="mt-radio mt-radio-outline">
Hayır
@Html.RadioButtonFor(model => model, false, ViewData["HtmlAttributes"], (bool?)Model == false)
<span></span>
</label>
</div>
}
else
{
<div class="mt-radio-inline">
<label class="mt-radio mt-radio-outline">
Evet
@Html.RadioButtonFor(model => model, 1, ViewData["HtmlAttributes"])
<span></span>
</label>
<label class="mt-radio mt-radio-outline">
Hayır
@Html.RadioButtonFor(model => model, 0, ViewData["HtmlAttributes"])
<span></span>
</label>
</div>
}
@Html.ValidationMessageFor(model => model, "", new { @class = "text-danger" })
@model bool?
<div class="mt-radio-inline">
<label class="mt-radio mt-radio-outline">
Evet
@Html.RadioButtonFor(model => model, true, ViewData["HtmlAttributes"])
<span></span>
</label>
<label class="mt-radio mt-radio-outline">
Hayır
@Html.RadioButtonFor(model => model, false, ViewData["HtmlAttributes"])
<span></span>
</label>
</div>
@Html.ValidationMessageFor(model => model, "", new { @class = "text-danger" })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment