jquery - using HtmlHelper in javascript with MVC and DataAnnotations jqGrid -


i created extension method works when not included in java script tag.

public static class extensionmethods {     public static string tickwrap(this htmlhelper source, mvchtmlstring mvchtmlstring)     {         return "'" + mvchtmlstring.tohtmlstring().replace("'", "''") + "'";     } } 

usage in view follows

@html.tickwrap(html.displaynamefor(m => model.sampledatetime)) 

all it's doing grabbing display name attribute of data annotation listed below , displaying 'date , time' ticks around it.

[display(name = "date , time")] public datetime sampledatetime {get; set;} 

i can't seem work in script tag however. getting javascript critical error syntax error. below script included in view.

<script type="text/javascript">     $(function () {         var displayname = @html.tickwrap(html.displaynamefor(m => model.sampledatetime))         alert(displayname);     }); </script> 

i'm guesing has usage of htmlhelper in script section? if how can use in script section?

that simplified version of have going on i'm trying populate colnames jqgrid without having hard code them in javascript. i'd use data annotations have change in 1 spot. colnames jqgrid gets defined

colnames: ['parameterid','location', 'parameter name', 'date , time', 'parameter value'] 

put '' (quotes) around @html.tickwrap(html.displaynamefor(m => model.sampledatetime))


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -