Within my partial view, I have implemented two buttons: Save and Preview. Both buttons are functioning as expected, with Preview enabling widget preview and Save saving data to the database. However, I am encountering two issues:
- I am unable to determine which button was clicked (within the onSuccess of Ajax.BeginForm).
- The controller is not redirecting to the specified action link.
Here is a snippet of my controller code:
public ActionResult EditWidget(WidgetViewModel viewmodel, string onSave, string onPreview)
{
if(!string.IsNullOrEmpty(onPreview))
{
// Code for handling Preview button click
}
else if(!string.IsNullOrEmpty(onSave))
{
// Code for handling Save button click
}
return null;
}
Below is my partial view:
@using (Ajax.BeginForm("EditWidget", "Home", new AjaxOptions { UpdateTargetId = "divPreview", HttpMethod = "POST", OnSuccess = "application.getpage.onSuccessPreview" }))
{
<!-- Form content here -->
}
And the onSuccess function:
onSuccessPreview: function (data, textStatus, jqXHR) {
// Need to identify which button was clicked in the partial view and handle redirection accordingly
}