gardarvalur gardarvalur - 7 months ago 93
Ajax Question

Call custom confirm dialog in Ajax.Beginform in MVC3

I want to be able to use a custom jquery dialog or at least be able to change the text of the buttons from OK/Cancel to something else when using the AjaxOptions.Confirm Property in the Ajax.Beginform function. Like this:

@using (Ajax.BeginForm("Function", "Controller", new { id = theId }, new AjaxOptions
HttpMethod = "POST",
UpdateTargetId = "theForm",
InsertionMode = InsertionMode.Replace,
LoadingElementId = "iconGif",
OnBegin = "OnBegin",
OnFailure = "OnFailure",
OnSuccess = "OnSuccess",
Confirm = "Are you sure?" //TODO: Confirm with different dialog?
}, new { id = "feedback-form" }))
//Some stuff
<button onclick="derp()">Submit</button>

Is there a way to achieve this with Ajax.Beginform through the AjaxOptions.Confirm Property?


No, you cannot achieve this with the Confirm property of AjaxOptions. This simply uses the window.confirm javascript method which doesn't allow any UI customizations and is browser dependent. You will have to implement this functionality yourself. For example you might want to checkout the jQuery UI dialog plugin.