Here is a custom JavaScript function that updates data when the Update button is clicked.
function UpdateData() {
var obj = {
"testData": $("#hdn_EditdsVal").val(),
"feature": $("#hdn_EditdsVal").val()
};
$.ajax({
url: '@(Url.Action("UpdatePlanFeatVal", "SuperAdmin"))',
type: "POST",
dataType: "json",
data: JSON.stringify(obj),
contentType: "application/json",
success: function (result) {
// Want to redirect the user using ControllerName/ActionMethod
},
error: function (err) {
}
});
}
And here's my controller:
public ActionResult UpdatePlanFeatVal(string testData, string feature)
{
var cmd = (object)null;
testData = testData.Trim();
string[] words = testData.Split(':');
XDocument _xdoc = new XDocument(new XElement("Pricing"));
foreach (string word in words)
{
if (!string.IsNullOrEmpty(word))
{
string[] wor = word.Split('_');
_xdoc.Root.Add(
new XElement("row",
new XElement("FeatureId", wor[1]),
new XElement("PlanId", wor[2]),
new XElement("Unit", wor[3])
));
}
}
using (StoredProcedureContext sc = new StoredProcedureContext())
{
cmd = sc.EditPricing(_xdoc);
}
return View("ManageSubscriptionPlan");
}
The redirection to the view is not happening as expected. After some research, I found that I may need to handle it in JavaScript itself and call the URL using the OnSuccess
option. Any tips on how to achieve this postback using JavaScript in my current situation?
Also, please note that the code has been modified before posting. I just want to ensure that the redirection occurs after the update.