2011-08-03 16 views
0

に設定されていません:日付時間は、私はasp.net MVC 3ビューのこの部分を持っているビュー

アクションdateOfBirthのがDatetime.minimum値に設定されているが、コントローラに
<tr> 
     <td>@Html.LabelFor(x => x.DateOfBirth, new { @class = "lbl" }, "Date Of Birth") </td> 
     <td>@Html.TextBoxFor(x => x.DateOfBirth, new { @class = "w100 _dob" }) 
     <br>@Html.ValidationMessageFor(x => x.DateOfBirth)  
     </td> 
    </tr> 

public ActionResult Index(IdentifyModel identifyModel) {} 

ビューのコード

@model CreditRegistry.Models.Helpers.IdentifyModel 

@{ 
    ViewBag.Title = "Identify"; 
    ViewBag.BreadCrumb = "Identify"; 
} 
@section BodyTitle { 
    <span>Identify</span> yourself 
} 
<ul class="extra"> 
    <li><a href="#">Receive Free Credit Report</a></li> 
    <li><a href="#">Premium Subscription</a></li> 
    <li><a href="#">FAQ</a></li> 
</ul> 


@using (Html.BeginForm("Index","Identify",FormMethod.Post,new{autocomplete="off", id="frmIdentify"})) { 


<p class="info"> 
    View and print your credit report after you authenticate your identity. <u><b>Your first 
     credit report is free.</b></u> 
</p> 


    <p> 
    Please provide as much information as you can so we can identify who you are. 
    Refer to the <b>@Html.ActionLink("FAQ", "FAQ", "Home")</b> for help. 
    </p> 

@* 
<p> 
    Is this report for an @Html.RadioButton("_mode", "_individualFields", true, new { @class = "_mode" }) 
    Individual or a @Html.RadioButton("_mode", "_businessFields", new { @class = "_mode" }) 
    Business? 
</p> 
*@ 


    @Html.ValidationSummary() 

<fieldset class="form"> 
<table> 
    <tr> 
     <td>@Html.LabelFor(x => x.FirstName, new { @class = "lbl" }, "First Name")</td> 
     <td>@Html.TextBoxFor(x => x.FirstName, new { @class = "w200" }) 
      <br>@Html.ValidationMessageFor(x => x.FirstName) 
     </td> 
    </tr> 
    <tr> 
     <td>@Html.LabelFor(x => x.LastName, new { @class = "lbl" }, "Last Name")</td> 
     <td>@Html.TextBoxFor(x => x.LastName, new { @class = "w200" }) 
     <br>@Html.ValidationMessageFor(x => x.LastName) 
     </td> 
    </tr> 
    <tr> 
     <td>@Html.LabelFor(x => x.DateOfBirth, new { @class = "lbl" }, "Date Of Birth") </td> 
     <td>@Html.TextBoxFor(x => x.DateOfBirth, new { @class = "w100 _dob" }) 
     <br>@Html.ValidationMessageFor(x => x.DateOfBirth)  
     </td> 
    </tr> 

    <tr> 
     <td>(optional)@Html.LabelFor(x => x.Phone, new { @class = "lbl" }, "Mobile Number") </td> 
     <td>@Html.TextBoxFor(x => x.Phone, new { @class = "w200" }) 
     <br>@Html.ValidationMessageFor(x => x.Phone) 
     </td> 
    </tr> 


    <tr> 
     <td>(optional)@Html.LabelFor(x => x.DLNumber, new { @class = "lbl" }, "Driver's License Number") </td> 
     <td>@Html.TextBoxFor(x => x.DLNumber, new { @class = "w200" }) 
     <br>@Html.ValidationMessageFor(x => x.DLNumber) 
     </td> 
    </tr> 
    <tr> 
     <td>(optional)@Html.LabelFor(x => x.PassportNo, new { @class = "lbl" }, "Passport Number") </td> 
     <td>@Html.TextBoxFor(x => x.PassportNo, new { @class = "w200" }) 
     <br>@Html.ValidationMessageFor(x => x.PassportNo) 
     </td> 
    </tr> 
    <tr> 
     <td>(optional)@Html.LabelFor(x => x.NationalID, new { @class = "lbl" }, "National ID") </td> 
     <td>@Html.TextBoxFor(x => x.NationalID, new { @class = "w200" }) 
     <br>@Html.ValidationMessageFor(x => x.NationalID) 
     </td> 
    </tr> 
</table> 
    <p> 
     <label> 
     </label> 
     <input type="submit" value="Start Identification" /> 
    </p> 
</fieldset> 

} 

<script type="text/javascript"> 
    $(function() { 
     $('#frmIdentify').attr('autocomplete', 'off'); @*make sure autocomplete off for browsers that already stored some information*@ 
     $('._dob').datepicker({ dateFormat: "yy-mm-dd", changeMoth: true, changeYear: true, yearRange: '-100y:c+nn' }); 
    }); 

ホーwを修正できます

+0

あなたの質問は明確ではありません –

答えて

0

DateOfBirthDateTime?データ型にする必要があります。 Nullable DateTimeです。つまり、DateOfBirthに値がない場合は、DateTime.MinValueではなくNULLになります。

public class IdentifyModel { 
    public DateTime? DateOfBirth {get;set;} 
} 

EDIT:

私はちょうどあなたの問題をreplciatedや修正を発見しました。あなたがNULL可能日時としてdateOfBirthのを宣言しなければなりませんIdentifyModelあなたのviewmodelクラスで

:これを行う

public DateTime? DateOfBirth { get; set; } 

は、ビューを得るとき01/01/0001を示す(または任意のデフォルトの日付がある)からの眺めを停止します。

次に、テキストボックスに「1/2/2010」と入力してフォームを投稿すると、DateTime値「1/2/2010」がビューモデルに戻されました。

+0

こんにちはジェイソン:ポイントは、私がテキストボックスに日付を入力しても、私はコントローラでそれを取得しません。 – DotnetSparrow

+0

ビュー用のコードをすべて投稿できますか? –

+0

私の質問を見てください。私はビューコードを追加しました – DotnetSparrow

0

ここでは複雑すぎます。あなたは分に設定されている日付を表示しません。 DateTimeフィールドがnullでない場合、null可能型は必要ありません。問題を再現する最も簡単なアプリを作成します。ブレークポイントを設定すると、Dateが表示されない理由がわかります。

関連する問題