2016-05-04 9 views
-1

私は質問が既に質問されていると思いますが、答えは私の問題のように見えます。mscorlib.dllで発生しましたが、ユーザーコードで処理されなかったSystem.FormatException 'を解決する方法

私はユーザーを選択しているグリッドを持っています。私は自分のIDをクリックすると、それは一部のユーザーに正常に動作し、いくつかのそれは、壊れてエラー以下示し

エラー:

An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code

Additional information: String was not recognized as a valid DateTime.

マイ

<div class="col-md-10"> 
    <input type="text" value='@DateTime.Parse(Model.IncidentDate.ToString()).ToString("dd/mm/yyyy"))' class="form-control input-xs" disabled /> 
</div> 

コーディングモデル

public string PNumber { get; set; } 
public DateTime? IncidentDate { get; set; } 
public string CNumber { get; set; } 

ありがとうございました..

+0

あなたは 'DateTime'が'に変換しているので文字列 'を生成し、結果の' string'をフォーマットで 'string'に再度変換します。 - ちょうど 'Model.IncidentDate.ToString(" dd/mm/yyyy ")'しかし、これのポイントは何と思いますか?あなたは何を達成しようとしていますか? –

+0

IncidentDateプロパティはnull可能です。 IncidentDateの値がnullの場合、例外がスローされますか? – MarcoLaser

+0

@StephenMuecke私はその形式で日付を持っていたい。私はちょうど私がそれをどうやって動かすことができるかわかりません。 – Mpho

答えて

0

次試してみてください。値がIncidentDateのために設定されていない

@Html.TextBoxFor(m => m.IncidentDate, "{0:dd/MM/yyyy}", new { @class = "form-control input-xs", disabled = "disabled" }) 

場合、それは空のテキストボックスが表示されます。値が設定されている場合、それは例えば、その中に日付とテキストボックスが表示されます。

04/05/2016 

を以下のように表す上記の値:

04 - dd 
05 - MM 
2016 - yyyy 
関連する問題