Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Can';不要让Jquery datepicker在我的asp.net mvc项目中工作_C#_Jquery_Asp.net Mvc_Jquery Ui - Fatal编程技术网

C# Can';不要让Jquery datepicker在我的asp.net mvc项目中工作

C# Can';不要让Jquery datepicker在我的asp.net mvc项目中工作,c#,jquery,asp.net-mvc,jquery-ui,C#,Jquery,Asp.net Mvc,Jquery Ui,我有一个简单的页面,我想在我的textboxfor中添加一个datepicker,只需修改格式,但页面上没有显示任何内容,我已尝试导入jquery datepicker文档中所需的所有脚本: 以下是我的cshtml页面,介绍了我目前试图使其正常工作的内容: @using System.Web.UI.WebControls @using InscriptionCentreFormation.Controllers @using InscriptionCentreFormation.Models @

我有一个简单的页面,我想在我的textboxfor中添加一个datepicker,只需修改格式,但页面上没有显示任何内容,我已尝试导入jquery datepicker文档中所需的所有脚本:

以下是我的cshtml页面,介绍了我目前试图使其正常工作的内容:

@using System.Web.UI.WebControls
@using InscriptionCentreFormation.Controllers
@using InscriptionCentreFormation.Models
@model INSC_Inscription
@{
 ViewBag.Title = "InscriptionFormation";
 Layout = "~/Views/Shared/_Layout.cshtml";
}
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<br />
@using (Html.BeginForm("InscriptionFormation", "DetailProduit"))
{
    @Html.HiddenFor(m => m.idOccurenceFormation);
    <div style="width:550px;">
        <br />
        <span style="float:left"><b>Date de naissance :</b></span>
        @Html.TextBoxFor(m => m.DateNaissanceChaine, new { Style = "float:right;width:350px;",id="datepicker" })
        <br />
        @Html.ValidationMessageFor(model => model.DateNaissanceChaine, "", new { @class = "text-danger"})      

        </div>
    <input type="submit" class="btn" value="S'inscrire" style="width:200px; text-align:center;"/>
}
<script>
$(document).ready(function () {
    $("#datepicker").datepicker({
        format: 'DD-MM-YYYY'
    });
});
</script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
最后我发现了问题,jquery ui似乎已经加载到布局页面上,并且由于加载了两次而产生了问题

 @Scripts.Render("~/bundles/jqueryui")
移动此脚本

<script>
$(document).ready(function () {
    $("#datepicker").datepicker({
        format: 'dd-mm-yy'
    });
});

$(文档).ready(函数(){
$(“#日期选择器”)。日期选择器({
格式:年月日
});
});
下面是Jquery导入

同时将
id=“datepicker”
移动到TextBoxFor()

移动此脚本

<script>
$(document).ready(function () {
    $("#datepicker").datepicker({
        format: 'dd-mm-yy'
    });
});

$(文档).ready(函数(){
$(“#日期选择器”)。日期选择器({
格式:年月日
});
});
下面是Jquery导入


同时将
id=“datepicker”
移动到TextBoxFor()

问题是因为在将
datepicker
库包含在页面中之前,您试图使用该库。将包含代码的
块放在对jQuery.js和jQueryUI.js的引用之后


$(文档).ready(函数(){
$(“#日期选择器”)。日期选择器({
格式:“DD-MM-YYYY”
});
});
还要注意的是,您将
日期选择器
id放在了验证标签上,而不是应该放在输入元素上:

@Html.TextBoxFor(m => m.DateNaissanceChaine, new { Style = "float: right; width: 350px;", id = "datepicker })
<br />
@Html.ValidationMessageFor(model => model.DateNaissanceChaine, "", new { @class = "text-danger" })      
@Html.TextBoxFor(m=>m.DateNaissanceChaine,新{Style=“float:right;width:350px;”,id=“datepicker})

@Html.ValidationMessageFor(model=>model.DateNaissanceChaine,“,new{@class=“text danger”})

我还强烈建议您将样式规则放在类中,然后将这些类添加到HTML中。将内联样式放在HTML中只会使代码变得混乱,并不能很好地分离关注点。问题在于,您试图在将
日期选取器
库包含在页面中之前使用它。请将
放入>在对jQuery.js和jQueryUI.js的引用之后包含代码的块


$(文档).ready(函数(){
$(“#日期选择器”)。日期选择器({
格式:“DD-MM-YYYY”
});
});
还要注意的是,您将
日期选择器
id放在了验证标签上,而不是应该放在输入元素上:

@Html.TextBoxFor(m => m.DateNaissanceChaine, new { Style = "float: right; width: 350px;", id = "datepicker })
<br />
@Html.ValidationMessageFor(model => model.DateNaissanceChaine, "", new { @class = "text-danger" })      
@Html.TextBoxFor(m=>m.DateNaissanceChaine,新{Style=“float:right;width:350px;”,id=“datepicker})

@Html.ValidationMessageFor(model=>model.DateNaissanceChaine,“,new{@class=“text danger”})


我还强烈建议您将样式规则放在类中,然后将这些类添加到HTML中。在HTML中添加内联样式只会使代码变得混乱,并且不能很好地分离关注点

,因为在初始化日期选择器之后,您正在加载
jquery
jquery ui
。您没有带有
id=“datepicker”
的文本框。将脚本更改为
$(“#DateNaissanceChaine”)。datepicker({…
(您已将
id
添加到验证消息占位符中)实际上他有一个带有
id=“datepicker”的元素
但它不是
textbox
。它是验证消息。dateformat无效。请使用'dd-mm-yy'不要更改问题中的代码,并使添加的注释和答案无效。因为您在初始化datepicker之后加载
jquery
jquery ui
。您没有包含h
id=“datepicker”
。将脚本更改为
$(“#DateNaissanceChaine”)。datepicker({…
(您已将该
id
添加到验证消息占位符中)实际上有一个具有
id=“datepicker”的元素
但它不是
文本框
。它是验证消息。您的日期格式无效。请使用“dd-mm-yy”不要更改问题中的代码并使添加的注释和答案无效。我将其放在前面,但页面上仍然没有显示任何内容,这是因为您在
验证消息f上设置了
日期选择器
id或者
,当它应该放在的
文本框中时。我为您更新了答案。如果是这种情况,请检查控制台并报告您发现的任何错误。您在问题中编辑的错误表示您没有正确包含jqueryUI,或者仍在尝试执行
datepicker()
放错了地方。与此隔离,您的代码工作正常:我猜问题出在我的项目中,所以感谢您的帮助,不管怎样我把它放在前面,但页面上仍然没有显示任何内容,这是因为您在
ValidationMessageFor
上设置了
日期选择器
id,而它应该放在
文本框中我的答案在这种情况下,请检查控制台并报告您发现的任何错误您在问题中编辑的错误意味着您没有正确包含jqueryUI,或者仍在尝试执行
datepicker()
放错地方了。单独地说,你的代码工作得很好:我想问题出在我的项目中,所以还是谢谢你的帮助