jQuery UI Datepicker 部署后未发布到服务器

发布于 2024-11-09 21:57:11 字数 2823 浏览 0 评论 0原文

因此,我发布了一个 ASP.Net MVC3 项目,该项目在 IIS 服务器上使用 jQuery UI 日期选择器。日期选择器似乎没有发布它们的值并在后端恢复为默认值。

在当地,尽管它很有魅力。这是简单的 jQuery,日期选择器上没有任何选项。

关于为什么会发生这种情况有任何线索吗?

让我知道我可以发布哪些内容来帮助找到解决方案。

谢谢!

我试图发回的模型:

public class Report
{
    [Required]
    [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
    public DateTime From { get; set; }
    [Required]
    [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
    public DateTime To { get; set; }

    public virtual Car Car { get; set; }
    public virtual IEnumerable<Review> Reviews { get; set; }
}

我正在使用的表单:

@model Cars.Models.Report

<h3>Create a report</h3>
@using (Html.BeginForm("Generate", "Report"))
{
<div>
    <div class="span-5">
        <div class="editor-label">
            @Html.LabelFor(model => model.From)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.From, new { @class = "datepicker lilbig" })
        </div>
    </div>

    <div class="span-5 last">
        <div class="editor-label">
            @Html.LabelFor(model => model.To)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.To, new { @class = "datepicker lilbig" })
        </div>
    </div>

    <div class="span-11 last">
        <div class="prepend-5 last">
            <input class="bigbtn" type="submit" value="Create" />
        </div>
        <div>
            @Html.ValidationSummary(true)
            @Html.ValidationMessageFor(model => model.From)
            @Html.ValidationMessageFor(model => model.To)
        </div>
    </div>
</div>
}

我发布到的方法:

[HttpPost]
    public ActionResult Generate(Report model)
    {
        try
        {
            MembershipUser currentUser = Membership.GetUser(HttpContext.User.Identity.Name);
            Guid id = (Guid)currentUser.ProviderUserKey;
            Car currentCar = CarRepository.Get(id);

            currentCar.LastReportCreated = DateTime.Now;
            currentCar = CarRepository.Update(currentCar, true);

            model.Car = currentCar;
            model.Reviews = model.Car.Reviews.Where(s => s.LoggedAt.Date >= model.From.Date &&
                                                               s.LoggedAt.Date <= model.To.Date);

            return View("Report", model);
        }
        catch(Exception ex)
        {
            return View("Error");
        }
    }

jQuery 看起来像这样:

$(document).ready(function () {
    $(".datepicker").datepicker();
});

So I published a ASP.Net MVC3 project that uses the jQuery UI datepickers on to a IIS server. The datepickers don't seem to post their values and revert to default values on the back end.

Locally, though it works like a charm. It's simple jQuery without any options on the datepicker.

Any clue as to why that would happen?

Let me know what I can post to help find a solution.

Thanks!

The model I am trying to post back:

public class Report
{
    [Required]
    [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
    public DateTime From { get; set; }
    [Required]
    [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
    public DateTime To { get; set; }

    public virtual Car Car { get; set; }
    public virtual IEnumerable<Review> Reviews { get; set; }
}

The form I am using:

@model Cars.Models.Report

<h3>Create a report</h3>
@using (Html.BeginForm("Generate", "Report"))
{
<div>
    <div class="span-5">
        <div class="editor-label">
            @Html.LabelFor(model => model.From)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.From, new { @class = "datepicker lilbig" })
        </div>
    </div>

    <div class="span-5 last">
        <div class="editor-label">
            @Html.LabelFor(model => model.To)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.To, new { @class = "datepicker lilbig" })
        </div>
    </div>

    <div class="span-11 last">
        <div class="prepend-5 last">
            <input class="bigbtn" type="submit" value="Create" />
        </div>
        <div>
            @Html.ValidationSummary(true)
            @Html.ValidationMessageFor(model => model.From)
            @Html.ValidationMessageFor(model => model.To)
        </div>
    </div>
</div>
}

Method I am posting to:

[HttpPost]
    public ActionResult Generate(Report model)
    {
        try
        {
            MembershipUser currentUser = Membership.GetUser(HttpContext.User.Identity.Name);
            Guid id = (Guid)currentUser.ProviderUserKey;
            Car currentCar = CarRepository.Get(id);

            currentCar.LastReportCreated = DateTime.Now;
            currentCar = CarRepository.Update(currentCar, true);

            model.Car = currentCar;
            model.Reviews = model.Car.Reviews.Where(s => s.LoggedAt.Date >= model.From.Date &&
                                                               s.LoggedAt.Date <= model.To.Date);

            return View("Report", model);
        }
        catch(Exception ex)
        {
            return View("Error");
        }
    }

The jQuery looks like this:

$(document).ready(function () {
    $(".datepicker").datepicker();
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽手叙旧 2024-11-16 21:57:11

检查服务器上的日期选择器版本是否是最新的并且运行时没有错误。在发布之前还要仔细检查您的表单数据 - 确保日期字段具有值:

$(document).ready(function () {

  $("form").submit(function(){
    $(".datepicker").each(function(){
      alert( $(this).attr("name") +": "+ $(this).value() );
    });
  });

});

Check that the datepicker version on the server is current and running bug-free. Also double check your form data before it gets posted - make sure the date fields have values:

$(document).ready(function () {

  $("form").submit(function(){
    $(".datepicker").each(function(){
      alert( $(this).attr("name") +": "+ $(this).value() );
    });
  });

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文