1-create Datetime.cshtml inside View->Shared->EditorTemplates folder.
Datetime.cshtml
@model DateTime?
@Html.TextBox("", Model.HasValue ? Model.Value.ToString("dd/MM/yyyy") : "", new { @class = "date" })
2- Goto create.cshtml inside user folder
create.cshtml
@model MyMVCAccount.Models.User
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
<link href="~/Content/Site.css" rel="stylesheet" />
<link href="~/Content/themes/base/jquery.ui.all.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.8.2.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="~/Scripts/jquery-ui-1.8.24.min.js"></script>
<script type="text/javascript">
$(function () {
$("input:text.date").datepicker({ dateformat: "dd/mm/yy" });
});
</script>
<table>
<tr>
<td>
@Html.ActionLink("Show Users", "Index")
</td>
</tr>
</table>
@using (Html.BeginForm())
{
<table style="margin-left:100px" width="100%">
<tr>
<td>
@Html.LabelFor(a => @Model.Name)
</td>
</tr>
<tr>
<td>
@Html.TextBoxFor(a => @Model.Name)
@Html.ValidationMessageFor(a => @Model.Name)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(a => @Model.LoginId)
</td>
</tr>
<tr>
<td>
@Html.TextBoxFor(a => @Model.LoginId)
@Html.ValidationMessageFor(a => @Model.LoginId)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(a => @Model.Password)
</td>
</tr>
<tr>
<td>
@Html.EditorFor(a => @Model.Password, new { @autocomplete = "off" })
@Html.ValidationMessageFor(a => @Model.Password)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(a => @Model.HireDate)
</td>
</tr>
<tr>
<td>
@Html.TextBoxFor(a => @Model.HireDate, new { @class="date"})
@Html.ValidationMessageFor(a => @Model.HireDate)
</td>
</tr>
<tr>
<td colspan="2">
<input id="Submit1" type="submit" value="submit" />
</td>
</tr>
</table>
}
@{
@*if (ViewData["result"] != "" && ViewData["result"] != null)
{
ViewData["result"] = null;
<script type="text/javascript" language="javascript">
alert("Data saved Successfully");
</script>
}*@
}
Datetime.cshtml
@model DateTime?
@Html.TextBox("", Model.HasValue ? Model.Value.ToString("dd/MM/yyyy") : "", new { @class = "date" })
2- Goto create.cshtml inside user folder
create.cshtml
@model MyMVCAccount.Models.User
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
<link href="~/Content/Site.css" rel="stylesheet" />
<link href="~/Content/themes/base/jquery.ui.all.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.8.2.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="~/Scripts/jquery-ui-1.8.24.min.js"></script>
<script type="text/javascript">
$(function () {
$("input:text.date").datepicker({ dateformat: "dd/mm/yy" });
});
</script>
<table>
<tr>
<td>
@Html.ActionLink("Show Users", "Index")
</td>
</tr>
</table>
@using (Html.BeginForm())
{
<table style="margin-left:100px" width="100%">
<tr>
<td>
@Html.LabelFor(a => @Model.Name)
</td>
</tr>
<tr>
<td>
@Html.TextBoxFor(a => @Model.Name)
@Html.ValidationMessageFor(a => @Model.Name)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(a => @Model.LoginId)
</td>
</tr>
<tr>
<td>
@Html.TextBoxFor(a => @Model.LoginId)
@Html.ValidationMessageFor(a => @Model.LoginId)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(a => @Model.Password)
</td>
</tr>
<tr>
<td>
@Html.EditorFor(a => @Model.Password, new { @autocomplete = "off" })
@Html.ValidationMessageFor(a => @Model.Password)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(a => @Model.HireDate)
</td>
</tr>
<tr>
<td>
@Html.TextBoxFor(a => @Model.HireDate, new { @class="date"})
@Html.ValidationMessageFor(a => @Model.HireDate)
</td>
</tr>
<tr>
<td colspan="2">
<input id="Submit1" type="submit" value="submit" />
</td>
</tr>
</table>
}
@{
@*if (ViewData["result"] != "" && ViewData["result"] != null)
{
ViewData["result"] = null;
<script type="text/javascript" language="javascript">
alert("Data saved Successfully");
</script>
}*@
}
No comments:
Post a Comment