单击按钮,以mvcforms触发模式弹出窗口

我在mvc中有这个视图,我在其中显示模型的详细信息。 模态弹出窗口工作正常,直到我没有把它放在窗体块中。 现在它只回发而不是显示弹出窗口。

这是我的观点:

@using App.Portal.WebUI.Controllers @using MvcPaging @model IPagedList @{ ViewBag.Title = "Manage Devices"; } 

Manage Devices

@Html.ActionLink("Add New Device", "Manage", "Handhelds", new { @class = "editUser btn btn-info" })

@using (Ajax.BeginForm("Home", "Handhelds", new AjaxOptions {UpdateTargetId = "grid-list", HttpMethod = "get", LoadingElementId = "loading", OnBegin = "beginPaging", OnSuccess = "successPaging", OnFailure = "failurePaging"}, new {id = "frm-search"})) {

@foreach (var device in Model) { }
No Device ID Serial Number Options
@device.DeviceID @device.DeviceIDView @device.DeviceSerialNumber @Html.ActionLink("Edit", "Manage", new {id = @device.DeviceID}, new {@class = "editUser btn btn-info"})
} $(document).ready(function () { $('button.btnAddDevice').click(function () { $('#addNewDevice').modal('show'); }); $('button.deleteHandheld').click(function () { $("#hfDeviceId").val($(this).data('id')); $('#deleteConfirm').modal('show'); }); $('button.deleteDeviceConfirm').click(function () { $.ajax({ url: '@Url.Action("Delete", "Handhelds")', data: { deviceid: $("#hfDeviceId").val() }, dataType: "json", type: 'POST', success: function (data) { if (data === "OK") { $('#deleteConfirm').modal('hide'); $('#deleteConfirmation').modal('show'); setTimeout(function () { location.reload(); }, 3000); } }, error: function (textStatus, errorThrown) { Success = false;//doesnt goes here } }); }); });

我需要id为btnDeleteHandheld的按钮来触发相关的模态弹出窗口。 任何人都可以给我一些建议我需要改变什么?

谢谢,Laziale

我认为该button默认提交输入。 为防止post使用preventDefault,如下所示:

  $('button.deleteHandheld').click(function (e) { e.preventDefault(); $("#hfDeviceId").val($(this).data('id')); $('#deleteConfirm').modal('show'); }); 

你也可以用这个替换你的按钮:

 Delete