Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC client side call to C# utility method from multiple views
    primarykey
    data
    text
    <p>I would like to know how to call a POCO class (static) C# utility method from AJAX (or jquery or javascript or whatever) from an MVC view. I want to call this utility method from a number of different views based on client-side user inputs (e.g., clicking the jquery fullcalendar eventClick) without having to integrate the utility with each view's controller. The ultimate goal is to render a colorbox modal dialog, or at least send the JQuery colorbox parameters/syntax back to the view to be executed in the view (client-side). The purpose of the server-side method is to standardize calls to jquery colorbox dialogs. I understand in principle that MVC controllers aren't tied to being used from particular views. So, how would I set up the controller with action methods for common utilities and how would I set up the call to the controller from the view? The view call will pass two string parameters (based on which event the user clicks) to the server-side utility method: key, identifier. The server-side method will do a lookup based on the key and pass back a string value containing the colorbox call that the JQuery function in the view will execute (or it could also be an object containing name/value pairs for the colorbox call parameters).</p> <p>Below is an example of the server-side utility class code (without supporting methods, etc.). Thanks in advance.</p> <pre><code>namespace UI.Utility.Details { public static class Details { [WebMethod] public static string CallColorbox(string key, string identifier, string colorboxCall) { if (string.IsNullOrEmpty(key)) throw new Exception("Error: No key supplied."); if (string.IsNullOrEmpty(identifier)) throw new Exception("Error: No identifier supplied."); DetailSettings settings = GetSettings(key, identifier); if (settings == null) throw new Exception(string.Format("Error: Settings not found for key [{0}].", key)); colorboxCall = null; if (settings != null) { //$.colorbox({iframe:true, innerWidth:500, innerHeight:350, href:newUrl, opacity:0.35, scrolling:false }); colorboxCall = string.Format( //"$.colorbox({ iframe:{0}, innerWidth:{1}, innerHeight:{2}, {3}:{4}, opacity:{5}, scrolling:{6} });", "{0} iframe:{1}, innerWidth:{2}, innerHeight:{3}, {4}:{5}, opacity:{6}, scrolling:{7} {8}", "{", settings.iframe, settings.innerWidth, settings.innerHeight, settings.identifierType, settings.identifier, settings.opacity, settings.scrolling, "}" ); } if (string.IsNullOrEmpty(colorboxCall)) throw new Exception(string.Format("Error: colorbox call not constructed for key [{0}].", key)); return colorboxCall; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload