New custom action in view page?

It is possible to add new action to “OtherOptions” in view page?

I am able to create new custom action in list page and now I am trying to create one in view page but I have no clue.
For example,
A “complete” button in view page next to add/edit/delete button. When I click on “complete” button, it will prompt a message for me to proceed to update selected fields or cancel the action.
Please advise,
Thank you.

on the list page you can do something like

// Page Load event
public void Page_Render() {
	//Log("Page Render");

	var importLink = OtherOptions["addedit"].Add("my_action");
				//check if its null to avaoid exceptions
				importLink.Body = "<a href='imported_filesadd' class='btn btn-default text-black fa fa-upload' style='margin-left:10px; margin-top:1px; font-size : 14px; '> Upload File</a>";
}

BUT on the view page we dont have OtherOptions called addedit, BUT if you open your project in like vidual studio and put a debug point in view page you will see they instead have Otheroptions called action, so your code becomes

// Page Load event
public void Page_Render() {
	//Log("Page Render");

	var importLink = OtherOptions["action"].Add("my_action");
				//check if its null to avaoid exceptions
				importLink.Body = "<a href='imported_filesadd' class='btn btn-default text-black fa fa-upload' style='margin-left:10px; margin-top:1px; font-size : 14px; '> Upload File</a>";
				
}

HINT you can also add buttons on ExportOptions etc etc, always refer to the generated views for the respective page to see how it drawing so you can know what to customise

Hi kirondedshem, thanks for the head up.I am debugging my code in VS2017 and I am able to see the “my_action” beside delete on view page base on your previous example. I will need all a C# function to do the update process.

I have tried the code below but it doesn’t call the function

var importLink = OtherOptions["action"].Add("my_action");
importLink.Body = "<a href='#' runat='server' OnServerClick='mynewfunction' class='btn btn-default text-black fa fa-upload' style='margin-left:10px; margin-top:1px; font-size : 14px; '> Complete </a>";

in the view page

public void mynewfunction()
		{
			my code...
		}

One way is, you can pass get paramter in the url in href foe example href=“mylink-----my_action_parameter=Action”, the link can even be calling the same view page and passing id os the record but also passing an extra parameter to indicate an actio to be done.
then you check for that parameter i page load of the view page, where if found you do your action for example

public void Page_Load() {
if(SameString(Get("my_action_parameter"),"Action"))
{
//put your code here
}

}

Then write jquery fucntion to call your custom controller action like so

$.post("update_employee_leave_plan", { "employee_leave_plan_id": employee_leave_plan_id, "full_day": full_day, "state": checked }, function (result) { // Post back your custom data (with the synchronizer token)
			
			console.log('got' + result);
			//var jsonresult = $.parseJSON(result);

		});

then call this fucntion onclick event of your button

Thank you very much kirondedshem, I have got it works perfectly via following your advice.

Hello,

Is there a better way to do this?It is very straightforward to execute custom action in the List page, thanks to Row_CustomAction.
But unfortunately, it Is missing from the View page.Would you please advise if there is a direct/easier way in v2021 to execute a custom server code (other than using API call)?

You can use the Page_Load server event to handle any post back calls.