tags:

views:

26

answers:

2

I have an MVC application with a link to print the information. the print link is inside a javascript. code as follows: <%= Html.TextBox("Name", Model.ApplicantStatus.Name) %> <%= Html.ValidationMessage("Name", "*") %>

<script type="text/javascript">
var myEmail = "[email protected]";
var mySubject = "Sample";
var myBody = "My name is ";
var myName = Model.TableName.Name;
document.write('<a href="mailto:' + myEmail + '?subject=' + mySubject + '&body=' + myBody + myname + '">email me</a>');
 </script>


basically var myName = Model.TableName.Name; is not working. any workarounds?

A: 

Try using <%= Model.TableName.name %>

griegs
+2  A: 

Wrap it in the string output tag and enclose it in quotes.

var myName = '<%= Model.TableName.Name %>';

You need to use the string output tag to get the actual content from the variable. It needs to be in quotes to treat it as a string, otherwise it attempts to find a javascript object with that name.

tvanfosson
Yeah, I forgot about that little detail.
griegs
that's so cool. thanks for all of the replies.
dmarkez
Although I just tried it w/out the quotes and it still works on mine.
griegs