@Html.LabelFor (model => model . NationalIDNumber)
@Html.EditorFor (model => model.NationalIdNumber) @ Html.ValidationMessageFor (model => model.NationalIdNumber)
@ Html . EditorFor (model => model.Login) @ Html.ValidationMessageFor (model => model.Login)@Html.LabelFor (model => Model.JobTitle)
@Html.EditorFor (model => model.JobTitle) @ Html.ValidationMessageFor (model => model.JobTitle)
@Html.LabelFor (model => model.BirthDate)@Html.EditorFor (model => model.BirthDate) @ Html.ValidationMessageFor (model => model.BirthDate)@Html.LabelFor (model => model.Maried)@Html.EditorFor ( model => model.Maried) @ Html.ValidationMessageFor (model => model.Maried)@Html.LabelFor (model => model.Gender)@Html.EditorFor (model => model.Gender) @ Html.ValidationMessageFor (model => model.Gender)@Html.LabelFor (model => model.HireDate)@Html.EditorFor (model => model.HireDate) @ Html.ValidationMessageFor (model => model.HireDate)then at runtime, the framework will select the widget HTML (input, select, etc ...) to display the most appropriate the properties of the model and AC on all of your views.The good news is that we ourselves can create templates for new types and even better to change the templates related to basic types (int, string, DateTime, etc. ..)Stop the crap, Datepicker place.Ok, we first create a folder under EditorTemplates Views / Shared and we place a new order which will be called DateTime.cshtml.
@ @ MVCTest model using DateTime? Html.Datepicker @ ("", Model.HasValue? Model.Value.ToShortDateString (): string.Empty, 0)
Note the simplicity, it does call an extension method (which we will study on) and it formats it very Slightly dated (ToShortDateString). Let's add a class in our project with the following code: using System.Collections.Generic
; using System.Web.Mvc; MVCTest namespace {public static class {public static JQueryHtmlHelpers MvcHtmlString Datepicker (this HtmlHelper HtmlHelper, string name, object value) {return System.Web.Mvc.Html.InputExtensions.TextBox (HtmlHelper, name, value, new Dictionary {{"class", "datepicker"}});}}}In this extension method we simply ask render a TextBox (input html) which has Applying the datepicker css class.
You'll understand it does is write a bit of jQuery in the master page for all the TexBox site with the class datepicker become magically DatePicker.
This is what happens:
I imagine all the widgets that can be integrated easily!
0 comments:
Post a Comment