-3

mvcビューでdatetime pickerを使用するにはどうすればよいですか?datetime pickerをeditortemplateとして使用する方法

EditorTemplate:ここDatetime.cshtml

@model DateTime? 
@Html.TextBox("", Model.HasValue ? Model.Value.ToString("dd/MM/yyyy"):"", new { @class = "datefield" }) 

Model : 
[Required] 
public DateTime DateOfBirth { get; set; }. 

Also jquery.ui.all.css is under my solution content>themes>base 

は、日付ピッカーが必要な部分図です。 Html.LabelFor @

@model PersonalDetails` 

` (モデル=> model.DateOfBirth) Html.EditorFor(モデル=> model.DateOfBirth、新しい{@プレースホルダ= "生年月日" @、@class = Html.ValidationMessageFor @ "日付フィールド"、@タイプ= "テキスト"})
(モデル=> model.DateOfBirth)

Here the date field is coming in the format specified in the Datetime editor template. But the calendor image is not coming. 
+0

[jQuery UI datepicker](https://jqueryui.com/datepicker/)を使用すると何が問題になります – Shyju

+0

サンプルコードを試しましたか?あなたは直面している問題は何ですか? – Shyju

+0

ブートストラップには日付ピッカーがありません。ブートストラップの日付ピッカーを書いた人がいます。 [私はあなたのためにgoogleしましょう](https://www.google.com/#pws=0&q=bootstrap+datepicker+) – Shyju

答えて

0

あなたはjQのためのエディタを設定していると仮定しますueryで日付ピッカー:

@Html.EditorFor(model => model.DateOfBirth, new { @placeholder = "Date Of Birth", @class = "datefield", @type="text" }) 

チェックあなたのJSコードは、ブラウザのデバッグで正常に動作している場合は、あなたの日付ピッカーのコードは次のようになります必要があります。そして、

<script type="text/javascript"> 
$(document).ready(function() { 
    $(".datefield").datepicker({ 
     changeMonth: true, 
     changeYear: true, 
     showButtonPanel: true, 
     showOtherMonths: true, 
     selectOtherMonths: true, 
     // other datepicker settings here as you want 
    }); 
}); 
</script> 

することを確認してくださいjQueryのUI CSSファイルが Layout.cshtml内部またはいずれかが含まれている作りますカレンダーの画像を日付エディタのほかに示すべきである。この段階で、あなたのページのheadタグ、内側:

<link rel="stylesheet" href="~/Content/themes/base/jquery.ui.all.css" type="text/css"> 
<script src="~/Scripts/jQuery-[version].js" type="text/javascript"> 
<script src="~/Scripts/jQuery-ui-[version].js" type="text/javascript"> 

は、これらのスクリプトとスタイルdeclaを簡素化するために、 MVCスタイル/スクリプトをバンドルすることをお勧めします。

関連する問題