I am currently working with MVC 4 and facing an issue where I have the same action name for multiple views. This makes it difficult to write JavaScript code in all pages individually. Can I simply write the JavaScript in the C# action result instead?
I attempted the following approach, but encountered an error:
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "swal({ title: 'Dear User', text: " + TempData["MACNotice"] + ", type: 'warning',}, function () { var zip_file_path = window.location.href + '/MACSetting.zip'; var zip_file_name = 'MAC Setting'; var a = document.createElement('a'); document.body.appendChild(a); a.style = 'display: none'; a.href = zip_file_path; a.download = zip_file_name; a.click(); document.body.removeChild(a);}););", true);
The error message states:
Argument 1: cannot convert from 'ParentLogins.Controllers.SigninController' to 'System.Web.UI.Control'
Argument 1: cannot convert from 'ParentLogins.Controllers.SigninController' to 'System.Web.UI.Page'
I would appreciate any assistance with this problem, as there are many views to handle. If writing JavaScript directly in C# is possible, please let me know. Otherwise, I am open to exploring other options for implementing JavaScript without having to include it in every view.