【发布时间】:2015-08-13 01:13:38
【问题描述】:
为什么没有来电
this.submit()
没有触发提交并调用我的控制器? Chrome中的开发工具说有错误并且该功能不存在!
$('form').submit(function(e) {
e.preventDefault();
var geocoder = new google.maps.Geocoder();
var address = document.getElementById('SearchQuery').value;
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
alert("Location found: " + results[0].geometry.location);
$(this).submit();
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
});
@using (Html.BeginForm("Search", "Home", FormMethod.Get)) {
<div class="form-group">
@Html.TextBoxFor(model => model.SearchQuery, new { @class = "form-control"}) @Html.ValidationMessageFor(model => model.SearchQuery, "", new { @class = "text-danger" }) @Html.ValidationMessageFor(model => model.Longitude, "", new { @class = "text-danger"
}) @Html.TextBoxFor(model => model.ClassDate, "{0:MM/dd/yyyy}", new { @class = "datefield form-control" }) @Html.ValidationMessageFor(model => model.ClassDate, "", new { @class = "text-danger" }) @Html.Hidden("latitude", Model.Latitude) @Html.Hidden("longitude",
Model.Longitude)
</div>
<button type="submit" id="submitSearch" class="btn btn-default">Search</button>
}
【问题讨论】:
-
表单是如何创建的……指定的
method是什么 -
html表单在哪里?请显示所有相关源代码。
-
试试改成
$(this).submit(); -
$(this).submit() 似乎也不起作用
-
啊,新代码。在
e.preventDefault();之后,添加myForm = $(this)行。然后把$(this).submit();改成myForm.submit();
标签: javascript jquery html asp.net-mvc razor