C# 在ASP.NET上放置日期格式
我在一个图书馆管理网站上工作。我在ASP.NET中设置日期时遇到一些问题 如何让应用程序用户在创建项目时选择当前日期格式 创建.csshtmlC# 在ASP.NET上放置日期格式,c#,asp.net,asp.net-mvc,datetime,C#,Asp.net,Asp.net Mvc,Datetime,我在一个图书馆管理网站上工作。我在ASP.NET中设置日期时遇到一些问题 如何让应用程序用户在创建项目时选择当前日期格式 创建.csshtml @model LibraryProject.LibraryItem @{ ViewBag.Title = "Create"; } <h2>Create</h2> @using (Html.BeginForm()) { @Html.AntiForgeryTo
@model LibraryProject.LibraryItem
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Book</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.CategoryId, "Category", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("CategoryId", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.CategoryId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Author, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Author, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Author, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Pages, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Pages, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Pages, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.IsBorrowable, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<div class="checkbox">
@Html.EditorFor(model => model.IsBorrowable)
@Html.ValidationMessageFor(model => model.IsBorrowable, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Borrower, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Borrower, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Borrower, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.BorrowDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.ValidationMessageFor(model => model.BorrowDate, "The date is created automatically.", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Type, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Type, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Type, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
@model LibraryProject.LibraryItem
@{
ViewBag.Title=“创建”;
}
创造
@使用(Html.BeginForm())
{
@Html.AntiForgeryToken()
书
@Html.ValidationSummary(true,“,new{@class=“text danger”})
@LabelFor(model=>model.CategoryId,“Category”,htmlAttributes:new{@class=“controllabel col-md-2”})
@DropDownList(“CategoryId”,null,htmlAttributes:new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.CategoryId,“,new{@class=“text danger”})
@LabelFor(model=>model.Title,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.Title,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.Title,“,new{@class=“text danger”})
@LabelFor(model=>model.Author,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.Author,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.Author,“,new{@class=“text danger”})
@LabelFor(model=>model.Pages,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.Pages,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.Pages,“,new{@class=“text danger”})
@LabelFor(model=>model.isbrookable,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.isBorrovable)
@Html.ValidationMessageFor(model=>model.IsBorrowable,“,new{@class=“text danger”})
@LabelFor(model=>model.借款人,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.借款人,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.借款人,“,新{@class=“text danger”})
@LabelFor(model=>model.brookdate,htmlAttributes:new{@class=“controllabel col-md-2”})
@Html.ValidationMessageFor(model=>model.BorrowDate,“日期是自动创建的。”,新的{@class=“text danger”})
@LabelFor(model=>model.Type,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.Type,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.Type,“,new{@class=“text danger”})
}
@ActionLink(“返回列表”、“索引”)
@节脚本{
@Scripts.Render(“~/bundles/jqueryval”)
}
如图所示,当用户创建一本书时,我想获取借阅日期,最好的方法是什么?使用
input
控件和type='date'
。您能给我一个代码示例吗@Jamshaidkamran这样做的一种方法是将其放入控制器操作中,实例化新对象,将所有字段设置为表单值,然后将Borrowdate设置为DateTime。现在,