Last active
September 21, 2017 10:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Kullanıma Örnek --> | |
@Html.EditorFor(model => model.StartDate, "Datetime", new { @params = new { ng_model = "vm.startDate" } }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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