2017-06-05 115 views
0

我想顯示日期只有沒有時間,但似乎沒有任何工作與MVC5。我需要使用TextboxFor而不是EditorFor。我試過:MVC5 TextboxFor顯示日期沒有時間

<td class="input-pricing">@Html.TextBoxFor(m => new ProjectPricing().UnitTypePriceEffDate,"{0:MM/dd/yy}", new {id = "model-effectiveDate", @class = "date" })</td> 

它仍然顯示時間。

UnitTypePriceEffDate is of DateTimeOffSet type. 

我克隆模式jQuery中:

$("#model-pricing-row").clone().attr("id", "pricing-row-" + i).appendTo("#pricing-table"); 
    $("#pricing-row-" + i + " #model-effectiveDate").attr("id", "effectiveDate-" + i); 
    $("#effectiveDate-" + i).attr("name", "Project.ProjectPricings[" + i + "].UnitTypePriceEffDate"); 
    $("#effectiveDate-" + i).val(selectedUnitTypePriceEffDate[i]); 

誰能幫助?謝謝!

+0

你有沒有試過用'EditorTemplate',例如'@model DateTimeOffset @ Html.TextBoxFor(m => m,「{0:MM/dd/yy}」,新的{@class =「date」})'? –

+0

是的,但它不適用於MVC5。它完全忽略了「{0:MM/dd/yy}」... – BYG

+0

問題似乎在這裏'new ProjectPricing()。UnitTypePriceEffDate'。我試着用你的代碼,沒有時間顯示日期。 – User3250

回答

1

試試下面的(我假設UnitTypePriceEffDate是DateTime類型):

<td class="input-pricing"> 
    @Html.TextBox("model-effectiveDate", 
        new ProjectPricing().UnitTypePriceEffDate.ToShortDateString(), 
        new { @class = "date" }) 
</td>