Asp.net mvc 使用jquery UI和mvc助手

Asp.net mvc 使用jquery UI和mvc助手,asp.net-mvc,jquery-ui,Asp.net Mvc,Jquery Ui,我想将jQueryUIDatePicker与ASP:NETMVC助手一起使用。以下是我的观点的源代码:我的问题是,如何使用@Html.Editorfor行作为jquery UI下拉列表?提前谢谢 为简洁起见,省略以下部分: <div> <div class="editor-label"> <label>Memuriyete başlangıç tarihiniz nedir? </label>

我想将jQueryUIDatePicker与ASP:NETMVC助手一起使用。以下是我的观点的源代码:我的问题是,如何使用@Html.Editorfor行作为jquery UI下拉列表?提前谢谢

为简洁起见,省略以下部分:

        <div>
        <div class="editor-label">
            <label>Memuriyete başlangıç tarihiniz nedir? </label>
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.MemuriyetBaslamaTarihi,null, new { id = "drpMemuriyetBaslama" })
            @Html.ValidationMessageFor(model => model.MemuriyetBaslamaTarihi)
        </div>
    </div>

<script>
    $(function () {
        $("#drpMemuriyetBaslama").datepicker();
    });
</script>

你想让内迪尔变得更年轻吗?
@EditorFor(model=>model.MemuriyetBaslamaTarihi,null,new{id=“drpMemuriyetBaslama”})
@Html.ValidationMessageFor(model=>model.MemuriyetBaslamaTarihi)
$(函数(){
$(“#drpMemuriyetBaslama”).datepicker();
});
脚本引用放在_Layout.cshtml中:

    <!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    <link href="/Content/Site.css" type="text/css" rel="stylesheet" />    
    <link href="/Scripts/jquery-ui.css" rel="stylesheet" />
    <link href="~/Scripts/MenuStyle.css" rel="stylesheet" />

    <script src="/Scripts/jquery-2.1.4.min.js"></script>
    <script src="/Scripts/jquery-ui-1.11.4.min.js"></script>
    <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>


</head>
<body>
    <div id="header">
        <div class="title">Lojman Bilgi Sistemi</div>
    </div>
    <div id="categories">
        @{ Html.RenderAction("Menu", "Nav"); }
    </div>
    <div id="content">
        @RenderBody()
    </div>
</body>
</html>

@视图包。标题
罗伊曼·比尔吉·西斯特米
@{Html.RenderAction(“菜单”、“导航”);}
@RenderBody()
下面是datepicker的示例用法:

您的

@Html.EditorFor(model => model.MemuriyetBaslamaTarihi, null, new { id = "drpMemuriyetBaslama" })
未生成具有
id=“drpMemuriyetBaslama”
的元素,因此

$("#drpMemuriyetBaslama").datepicker();
将引发错误,因为未定义
$(“35;drpMemuriyetBaslama”)

除非您使用MVC-5.1或更高版本,否则无法使用
EditorFor()
方法添加html属性,如果是,则需要修改语法

@Html.EditorFor(m => m.MemuriyetBaslamaTarihi, new { htmlAttributes = new { id = "drpMemuriyetBaslama" } })
所有生成表单控件的HTMLHelper都会根据属性名添加一个默认的
id
属性(在您的情况下,它将是
id=“MemuriyetBaslamaTarihi”
),因此,除非您有更改它的特定原因,否则您只需使用

@Html.EditorFor(m => m.MemuriyetBaslamaTarihi)

或者,如果要更改默认的
id
属性,请使用

@Html.TextBoxFor(m => m.MemuriyetBaslamaTarihi, new { id = "drpMemuriyetBaslama" })

你忘了写你的问题了!除非您使用MVC-5.1或更高版本,否则无法使用
EditorFor()
添加html属性(如果是这样的话,您还是做错了)。删除新的{id=“drpMemuriyetBaslama”}并使用默认的
id
属性
$(“#MemuriyetBaslamaTarihi”).datepicker()
或使用
TextBoxFor()
是否有特定原因覆盖由助手生成的默认
id
属性?对不起,我忘记写我的问题了。谢谢Stephen Muecke先生。我想把你的答案设为真实答案。
@Html.TextBoxFor(m => m.MemuriyetBaslamaTarihi, new { id = "drpMemuriyetBaslama" })