English 中文(简体)
页: 1
原标题:asp.net mvc 3 razor & jquery ui datepicker

i 想在我的时日文本箱上显示破碎日期。

我在意见/共享/EditorTemplate中编造了日期。

@model Nullable<System.DateTime>
@if (Model.HasValue)
{
    @Html.TextBox("", String.Format("{0:yyyy-MM-dd HH:mm}", Model.Value), new { @class = "date" })
}
else
{
    @Html.TextBox("", String.Format("{0:yyyy-MM-dd HH:mm}", ""), new { @class = "date" })
}
@{
    string name = ViewData.TemplateInfo.HtmlFieldPrefix;
    string id = name.Replace(".", "_");
}
<reference path="jquery-1.4.4.js" />
<reference path="jquery-ui.js" />
<script type="text/javascript">
    $(document).ready(function () {
        $(".date").datepicker
            ({
                dateFormat:  dd/mm/yy ,
                showStatus: true,
                showWeeks: true,
                highlightWeek: true,
                numberOfMonths: 1,
                showAnim: "scale",
                showOptions: {
                    origin: ["top", "left"]
                }
            });
    });
</script>

我认为:

<td>
                <div class="editor-label" >
                    @Html.LabelFor(model => model.Birthdate)
                </div>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Birthdate, null, new { @class = "date"})
                    @Html.ValidationMessageFor(model => model.Birthdate)
                </div>
</td>

我在实体ado模式中的模式:

 public Nullable<global::System.DateTime> Birthdate
        {
            get
            {
                return _Birthdate;
            }
            set
            {
                OnBirthdateChanging(value);
                ReportPropertyChanging("Birthdate");
                _Birthdate = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("Birthdate");
                OnBirthdateChanged();
            }
        }

但它没有做任何工作,一是添加了<代码>(日期”).click(功能--alert(Clicked )}); 。

感谢

Browser html

<!DOCTYPE html>

<html>

<head>

    <title>Add Client - Lombard Admin Panel</title>

    <link href="/Content/Site.css" rel="stylesheet" type="text/css" />

    <script src="/Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>

    <script src="/Scripts/jquery-ui.js" type="text/javascript"></script>

    <link href="/Content/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />

</head>

<body>

    <div>

        <div id="top-bar">

            <div class="page-full-width cf">

                <ul id="nav" class="fl">

                    <li class="v-sep"><a href="#" class="round button dark ic-left-arrow image-left">მთავარი

                        საიტი</a></li>

                    <li class="v-sep"><a href="/home" class="round button dark home-left image-left">სახლი

                    </a></li>

                    <li class="v-sep"><a href="#" class="round button dark menu-user image-left">შესული

                        ხართ როგორც: <strong>acid</strong></a>

                        <ul>

                            <li><a href="#">ლომბარდის პროფილი</a></li>

                            <li><a href="#">პარამეტრები</a></li>

                            <li><a href="#">პაროლის შეცვლა</a></li>

                            <li><a href="/logout">გასვლა</a></li>

                        </ul>

                    </li>

                    <li><a href="#" class="round button dark menu-email-special image-left">3 ახალი შეტყობინება</a></li>

                    <li><a href="#" class="round button dark menu-logoff image-left">გასვლა</a></li>

                </ul>

            </div>

        </div>

        <div id="header-with-tabs">

            <div class="page-full-width cf">

                <a href="#" id="company-branding-small" class="fr">

                    <img src="/Content/images/company-logo.png" alt="Blue Hosting" /></a>

            </div>

        </div>

        <div id="content">

            <div class="page-full-width cf">

                <div class="side-menu fl">

                    <h3>

                        მთავარი მენიუ</h3>

                    <ul>

                        <li><a href="#">დამატება/რედაქტირება</a>

                            <ul>

                                <li><a href="#">ფილიალები</a></li>

                                <li><a href="/client">კლიენტები</a></li>

                                <li><a href="#">მომხმარებლები</a></li>

                                <li><a href="details.aspx">კომპანიის დეტალები</a></li>

                            </ul>

                        </li>

                        <li><a href="#">საწყობი</a></li>

                        <li><a href="#">შემოსავლები</a></li>

                        <li><a href="#">გაყიდვების ისტორია</a></li>

                        <li><a href="#">ანალიზი</a></li>

                    </ul>

                </div>

                <div class="side-content fr">

                    <div class="content-module">

                        <div id="render-body">

                            <h1>

    ახალი კლიენტის დამატება</h1>

<br />

<script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>

<script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>

<script src="/Scripts/jquery-ui.js" type="text/javascript"></script>

<script src="/Scripts/jquery-1.4.4.js" type="text/javascript"></script>

<link href="/Content/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />



<form action="/client/Create" method="post">    <table>

        <tr>

            <td>

                <div class="editor-label">

                    <label for="Firstname">სახელი</label>

                </div>

                <div class="editor-field">

                    <input class="text-box single-line" id="Firstname" name="Firstname" type="text" value="" />

                    <span class="field-validation-valid" data-valmsg-for="Firstname" data-valmsg-replace="true"></span>

                </div>

                <div class="editor-label">

                    <label for="Lastname">გვარი</label>

                </div>

                <div class="editor-field">

                    <input class="text-box single-line" id="Lastname" name="Lastname" type="text" value="" />

                    <span class="field-validation-valid" data-valmsg-for="Lastname" data-valmsg-replace="true"></span>

                </div>

                <div class="editor-label">

                    <label for="IsMale">სქესი</label>

                </div>

                <div class="editor-field">

                    <select class="list-box tri-state" id="IsMale" name="IsMale"><option selected="selected" value="">Not Set</option>

<option value="true">True</option>

<option value="false">False</option>

</select>

                    <span class="field-validation-valid" data-valmsg-for="IsMale" data-valmsg-replace="true"></span>

                </div>

            </td>

            <td>

                <div class="editor-label" >

                    <label for="Birthdate">დაბადების თარიღი</label>

                </div>

                <div class="editor-field">

                    <input class="date" id="Birthdate" name="Birthdate" type="text" value="" /><reference path="jquery-1.4.4.js" />

<reference path="jquery-ui.js" />

<script type="text/javascript">

    $(document).ready(function () {

        $(".date").click(function{

        alert( Boo )

        });

        $(".date").datepicker

            ({

                dateFormat:  dd/mm/yy ,

                showStatus: true,

                showWeeks: true,

                highlightWeek: true,

                numberOfMonths: 1,

                showAnim: "scale",

                showOptions: {

                    origin: ["top", "left"]

                }

            });

    });

</script>



                    <span class="field-validation-valid" data-valmsg-for="Birthdate" data-valmsg-replace="true"></span>

                </div>

                <div class="editor-label">

                    <label for="PrivateNumber">პირადი ნომერი</label>

                </div>

                <div class="editor-field">

                    <input class="text-box single-line" id="PrivateNumber" name="PrivateNumber" type="text" value="" />

                    <span class="field-validation-valid" data-valmsg-for="PrivateNumber" data-valmsg-replace="true"></span>

                </div>

                <div class="editor-label">

                    <label for="Address">მისამართი</label>

                </div>

                <div class="editor-field">

                    <input class="text-box single-line" id="Address" name="Address" type="text" value="" />

                    <span class="field-validation-valid" data-valmsg-for="Address" data-valmsg-replace="true"></span>

                </div>

            </td>

            <td>

                <div class="editor-label">

                    <label for="Phone1">ტელ. 1</label>

                </div>

                <div class="editor-field">

                    <input class="text-box single-line" id="Phone1" name="Phone1" type="text" value="" />

                    <span class="field-validation-valid" data-valmsg-for="Phone1" data-valmsg-replace="true"></span>

                </div>

                <div class="editor-label">

                    <label for="Phone2">ტელ. 2</label>

                </div>

                <div class="editor-field">

                    <input class="text-box single-line" id="Phone2" name="Phone2" type="text" value="" />

                    <span class="field-validation-valid" data-valmsg-for="Phone2" data-valmsg-replace="true"></span>

                </div>

                <div class="editor-label">

                    <label for="Email">ელ-ფოსტა</label>

                </div>

                <div class="editor-field">

                    <input class="text-box single-line" id="Email" name="Email" type="text" value="" />

                    <span class="field-validation-valid" data-valmsg-for="Email" data-valmsg-replace="true"></span>

                </div>

            </td>

        </tr>

    </table>

    <br />

    <p>

        <input type="submit" value="დამატება" class="button round blue image-right ic-add text-upper" />

    </p>

</form><div>

    <a href="/client">უკან დაბრუნება</a>



</div>



                        </div>

                    </div>

                </div>

            </div>

        </div>

        <div id="footer">

            <p>

                &copy; Copyright 2012 <a href="#">Acid Labs 2011</a>. All rights reserved.</p>

            <p>

                <strong>Lombard Admin Panel </strong>V 1.0 <a href="http://www.acidlabs.ge">Acid Labs</a></p>

        </div>

    </div>

</body>

</html>
最佳回答

你有一些问题。 首先,你们需要删除贵方模板中的参照标语,这些标语是合法的。 这并不是你如何使用参考标签。

第二, 你不想包括文字标签,否则,如果你在网页上有不止一个日期,就会多次执行该守则。

其次,你可以这样做:

@Html.EditorFor(model => model.Birthdate, null, new { @class = "date"}) 

编辑模板并不包含html的属性。 你还重新确定了一个无效的模板(第二个参数),因此它根本不使用任何模板,尽管你的模板的名称是:日期.cshtml,但这优先于模板选择。

这也是:

@Html.EditorFor(model => model.Birthdate)

此外,从全球的角度来看:在你们的财产的类型定义中,确保你们在使用清单中包含系统。 不能确定全球:将干预类型解决。

问题回答

Okay I had a similar problem and this is how I solved my issue:

我在意见/共享/企业家精神中设立了一个用户委员会,称为“Datetime”(Datetime.ascx)。

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %>
<%: Html.TextBox("",  String.Format("{0:yyyy-MM-dd}", Model.HasValue ? Model : DateTime.Today), new { @class = "dp"})%>

我的看法是这样:

<div class="editor-field">
        @Html.EditorFor(model => model.ReleaseDate) 
        @Html.ValidationMessageFor(model => model.ReleaseDate)
    </div>

我的描述就是这样:

<script type="text/javascript">
$(function () {
    $(".dp").datepicker();
});

这些是我所补充的联系(如果你没有的话):

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.ui.datepicker.min.js") " type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.ui.datepicker.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.ui.core.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.ui.core.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/DatePickerReady.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/themes/base/jquery.ui.datepicker.css")" type="text/css" rel="Stylesheet"/>
<link href="@Url.Content("~/Content/themes/base/jquery.ui.core.css")" type="text/css"/ rel="Stylesheet"/>
<link href="@Url.Content("~/Content/themes/base/jquery.ui.theme.css")" type="text/css" rel="Stylesheet"/>




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签