【问题标题】:jQuery UI Datepicker not Posting to Server after Deployment部署后 jQuery UI Datepicker 未发布到服务器
【发布时间】:2011-05-24 17:40:56
【问题描述】:

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

在本地,虽然它就像一个魅力。这是一个简单的 jQuery,在 datepicker 上没有任何选项。

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

让我知道我可以发布什么来帮助找到解决方案。

谢谢!

我要回传的模型:

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();
});

【问题讨论】:

    标签: asp.net-mvc-3 jquery-ui-datepicker form-data


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-09
      • 1970-01-01
      • 1970-01-01
      • 2018-08-25
      • 2017-12-14
      • 2015-03-03
      • 1970-01-01
      相关资源
      最近更新 更多