Skip to content

Instantly share code, notes, and snippets.

@mahmut-gundogdu
Last active September 21, 2017 10:50
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/85ad3e486a67da710f8ade792afe693e to your computer and use it in GitHub Desktop.
Save mahmut-gundogdu/85ad3e486a67da710f8ade792afe693e to your computer and use it in GitHub Desktop.
Editorfor için default cssClass ataması ve ek property verip aynı zamanda üstviewden parametre gönderebilmeye örnek.
<!-- Kullanıma Örnek -->
@Html.EditorFor(model => model.StartDate, "Datetime", new { @params = new { ng_model = "vm.startDate" } })
//EditorFordaki viewData parametremizi aldık.
var dataFromViewData = ViewData["params"];
IDictionary<string, object> htmlAttributes = new Dictionary<string, object>();
//Reflection ile property ad ve değerlerini aldık.
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(dataFromViewData.GetType()))
{
htmlAttributes.Add(property.Name, property.GetValue(dataFromViewData));
}
//default değerlerimizi atadık.
htmlAttributes.Add("class", "form-control date-picker");
htmlAttributes.Add("placeholder", "Lütfen Tarih Seçiniz.");
<div class="input-group date">
@Html.TextBoxFor(model => Model, "{0:dd'/'MM'/'yyyy}", htmlAttributes)
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment