asp.net mvc - JavaScript in MVC Editor template doesn't render properly -


i'm moving controls view editor. in editor have hiddenfor:

@html.hiddenfor(m => m.emaildatavariables) 

i have javascript tries read (this works in original page, not in view):

var myvalue = document.getelementbyid('emaildatavariables').value; 

the hiddenfor renders out (which breaks above javascript):

<input id="emailtemplate_emaildatavariables"      name="emailtemplate.emaildatavariables"      type="hidden"      value="mydata"> 

should assume control named emailtemplate.emaildatavariables , write javascript this:

var myvalue = document.getelementbyid('emailtemplate.emaildatavariables').value; 

or there better way handle this?

you have 2 options.

1) assume id emailtemplate_emaildatavariables , update js accordingly.

2) give unique id know.

@html.hiddenfor(m => m.emaildatavariables, new {id = "emaildatavariables"}) 

source


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo