What I'm trying to do is write javascript mixed with markup and methods containing a razor in a .cshtml file and send it to a separate method for use later.
My .cshtml looks something like this:
@{SomeClass.SaveForLater(@<script type="text/javascript">window.alert('@Model.SomeParamter')}</script>);
And inside the SomeClass class:
public static void SaveForLater(HtmlString str) {
But I get an error message:
CS1660: Unable to convert lambda expression to enter "System.Web.HtmlString" because it is not a delegate type
Am I using the wrong type of argument or do I need to rethink the whole concept?
Solution Thanks to the SLaks below, I ended this:
public static void SaveForLater<T>(Func<T, HelperResult> template, dynamic model) {
Using it as follows:
@{SomeClass.SaveForLater<SomeModel>( @<script type="text/javascript">window.alert('@Model.SomeParamter')</script>, Model );
source share