jQuery UI Datepicker 部署后未发布到服务器
因此,我发布了一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查服务器上的日期选择器版本是否是最新的并且运行时没有错误。在发布之前还要仔细检查您的表单数据 - 确保日期字段具有值:
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: