开发者

jQuery Datepicker problem on ASP.NET MVC action while works fine on another action

开发者 https://www.devze.com 2023-02-13 01:34 出处:网络
I\'ve encounter a strange behavior with the jQueryUI DatePicker on my blog app.It shows up correctly when I compose a new post, but when I edit on an existing post, the Datapicker lost it styles and l

I've encounter a strange behavior with the jQueryUI DatePicker on my blog app. It shows up correctly when I compose a new post, but when I edit on an existing post, the Datapicker lost it styles and localization.The compose and edit actions share the same view.

<script type="text/javascript" src="http://www.google.com/jsapi"></script> 
<script type="text/javascript">
    google.load("jquery", "1.4.4");
    google.load("jqueryui", "1.8.9");
</script> 
<script src="../../Scripts/jquery.ui.datepicker-zh-CN.js" type="text/javascript"></script>
<script>
$(function () {
    $("#Date").datepicker($.datepicker.regional["zh-CN"]);
});
</script> 
&开发者_运维问答lt;input id="Date" name="Date" type="text" value="@Model.Date" tabindex="2" style="width:100px" />

Here is action method when compose a new post

    [Authorize]
    public ActionResult Compose()
    {
        string date = DateTime.Now.ToString("yyyy-MM-dd");
        return View(new BlogPostComposeModel { Date = date, Body = "", Title = "", Tags = "" });
    }

Here is the action method when edit an existing post, this is when the Datepicker lost its styles and localization.

    [Authorize]
    public ActionResult Edit(string postID)
    {
        BlogPost post = // get post from data source
        string date = post.DateCreated.ToString("yyyy-MM-dd");

        return View("Compose", new BlogPostComposeModel { Date = date, Body = post.Body, Title = post.Title, Tags = tagNames });
    }


Any chance using Url.Content help at all?

<script src='@Url.Content("~/Scripts/jquery.ui.datepicker-zh-CN.js")' type="text/javascript"></script>

And also for you css

<link href='@Url.Content("~/Content/themes/something.css")' rel="stylesheet" type="text/css" />
0

精彩评论

暂无评论...
验证码 换一张
取 消