我是ASP.NET MVC的新手。通常情况下,我使用input:
在数据库中获取日期数据<input type="text" class="form-control datetime Tarih" name="SozBasTarihi" value="@(Model.SozBasTarihi!=null?Model.SozBasTarihi.Value.ToString("dd.MM.yyy"):"")" />
但是我想用select选项做这个,我想分别考虑日,月和年。我尝试过这样的事情,但我失败了。我们可以不在选择选项中使用“值”吗?我怎么能这样做?
<fieldset class="date">
<label for="day_start">Day</label>
<select id="day_start" name="SozBasTarihi" value="@(Model.SozBasTarihi!=null?Model.SozBasTarihi.Value.Day.ToString():"")">
@for (int i = 1; i < 31; i++)
{
<option>@i</option>
}
</select> -
<label for="month_start">Month</label>
<select id="month_start" name="SozBasTarihi" value="@(Model.SozBasTarihi!=null?Model.SozBasTarihi.Value.Month.ToString():"")">
<option>Ocak</option>
<option>Şubat</option>
<option>Mart</option>
<option>Nisan</option>
<option>Mayıs</option>
<option>Haziran</option>
<option>Temmuz</option>
<option>Ağustos</option>
<option>Eylül</option>
<option>Ekim</option>
<option>Kasım</option>
<option>Aralık</option>
</select> -
<label for="year_start">Year</label>
<select id="year_start" name="SozBasTarihi" value="@(Model.SozBasTarihi!=null?Model.SozBasTarihi.Value.Year.ToString():"")">
@for (int i = 2000; i < 2030; i++)
{
<option>@i</option>
}
</select>
<span class="inst">(Day-Month-Year)</span>
</fieldset>
我改变了我的代码,但我还没有找到解决方案:
<fieldset class="date">
<label for="day_start">Day</label>
<select id="day_start" name="SozBasTarihi" value="@(Model.SozBitisTarihi != null ? string.Format("{0:dd}", Model.SozBitisTarihi.Value) : "")">
@for (int i = 1; i < 31; i++)
{
<option>@i</option>
}
</select> -
<label for="month_start">Month</label>
<select id="month_start" name="SozBasTarihi" value="@(Model.SozBitisTarihi != null ? string.Format("{0:mm}", Model.SozBitisTarihi.Value): "")">
<option>Ocak</option>
<option>Şubat</option>
<option>Mart</option>
<option>Nisan</option>
<option>Mayıs</option>
<option>Haziran</option>
<option>Temmuz</option>
<option>Ağustos</option>
<option>Eylül</option>
<option>Ekim</option>
<option>Kasım</option>
<option>Aralık</option>
</select> -
<label for="year_start">Year</label>
<select id="year_start" name="SozBasTarihi" value="@(Model.SozBitisTarihi != null ? string.Format("{0:yyyy}", Model.SozBitisTarihi.Value): "")">
@for (int i = 2000; i < 2030; i++)
{
<option>@i</option>
}
</select>
<span class="inst">(Day-Month-Year)</span>