Reputation: 31416
I'm working on an ASP.NET MVC 3 application and having some issues. I've got a PartialView which has a submit button. Code looks something like this:
@using (Html.BeginForm("Edit", "IceCream", FormMethod.Post, new { id = "editicecreamform" + @Model.IceCreamID }))
{
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
@Html.TextBoxFor(model => model.FirstDateTime, new { @class = "mydatetime" })
@Html.ValidationMessageFor(model => model.FirstDateTime)
@Html.TextBoxFor(model => model.SecondDateTime, new { @class = "mydatetime" })
@Html.ValidationMessageFor(model => model.FirstDateTime)
<input type="submit" value="Save" data-icecream="@Model" />
}
and the script portion looks like this:
<script type="text/javascript">
$('.mydatetime').datetimepicker({
showSecond: true,
timeFormat: 'hh:mm:ss TT',
hourGrid: 4,
minuteGrid: 10
});
$(document).ready(function () {
var options = {
target: "#icecreamdetails@(Model.IceCreamID)",
url: '@Url.Action("Edit", "IceCream")',
success: UpdateGrid // not germane to discussion
};
$("#editicecreamform@(Model.IceCreamID)").submit(function () {
$(this).ajaxSubmit(options);
return false;
});
});
</script>
My Edit action looks something like:
[HttpPost]
public PartialViewResult Edit(IceCreamCreateEditViewModel viewModel)
{
if (ModelState.IsValid)
{
}
return PartialView();
}
The error occurs when I edit an entry and make the Name field blank and try to save it. There's a [Required]
annotation on the property in the viewmodel and so I get the validation error message. However, if I then attempt to click on one of my two datetime edits, I get a "too much recursion" or stackoverflow error. This occurs in FF as well as IE8. The error is in the jquery-ui-datetimepicker-addon.js
file that I'm using, which I got from http://trentrichardson.com/2010/04/19/timepicker-addon-for-jquery-ui-datepicker, at least that's where the debugging tool leads me.
If I just use the jquery datepicker (no time component), I don't get this error at all.
I assume there could be an error in the datetimepicker but as I'm new to jquery and ASP.NET MVC, there's a good chance it's just me not doing something correctly.
Any ideas?
Upvotes: 2
Views: 1980
Reputation: 31416
So, it appears that the problem is that my partial view has this line:
<script src="@Url.Content("~/scripts/jquery-ui-datetimepicker-addon.js")" type="text/javascript"></script
and if I move that into the _Layout.cshtml
instead, it doesn't get referenced twice and the "too much recursion" / stackoverflow issue.
Upvotes: 1