Thursday, January 2, 2014

Accessing Model property in MVC View from Javascript

For example, you have following model in your MVC application:

public class Employee
{
public string EmployeeName
public int EmployeeNumber
}

You have bound this model to your MVC view (Razor/ Html), and there may be a case when you need to access "EmployeeName" in the Javascript from that view.

You can access value of "EmployeeName" property of your model by following way:

<script type="text/javascript">
function showEmployeeName()
{
alert('@(Model.EmployeeName)');
}

</script>

43 comments:

  1. FFS! I've just spent the whole night trying to get a string value from my model into my JS. And it all came down to quotes! Cooking with gas now :-) Many thanks.

    ReplyDelete
  2. Great! Thanks a lot!

    ReplyDelete
  3. One help i want to loop one Model property that property in string[] in jquery.can u please tell how to do that?
    Thanks in advance

    ReplyDelete
  4. This is an amazing blog,it gives very helpful messages to us.Besides that Wisen has established as Best Dot Net Training in Chennai. or learn thru ASP.NET Online Training . Nowadays Dot Net has tons of job opportunities on various vertical industry.

    ReplyDelete
  5. Awesome article. It is so detailed and well formatted that i enjoyed reading it as well as get some new information too.
    Best Devops online Training
    Online DevOps Certification Course - Gangboard

    ReplyDelete
  6. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..
    Selenium training in Chennai

    Selenium training in Bangalore

    Selenium training in Pune

    Selenium Online training

    ReplyDelete
  7. Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us
    python Training in Pune
    python Training in Chennai
    python Training in Bangalore

    ReplyDelete
  8. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
    microsoft azure training in bangalore
    rpa training in bangalore
    best rpa training in bangalore
    rpa online training

    ReplyDelete
  9. Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
    python training in bangalore

    ReplyDelete

  10. awesome blog it's very nice and useful i got many more information it's really nice i like your blog styleweb design company in velachery

    ReplyDelete
  11. Attend The Machine Learning Training in Bangalore From ExcelR. Practical Machine Learning Training in Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Machine Learning Training in Bangalore.
    ExcelR Machine Learning Training in Bangalore

    ReplyDelete
  12. Your articles really impressed for me,because of all information so nice.devops Training in Bangalore

    ReplyDelete
  13. These provided information was really so nice,thanks for giving that post and the more skills to develop after refer that post.Amazon web services Training in Bangalore

    ReplyDelete
  14. I gathered a lot of information through this article.Every example is easy to undestandable and explaining the logic easily.python training in bangalore

    ReplyDelete
  15. Very useful and information content has been shared out here, Thanks for sharing it.selenium training in bangalore

    ReplyDelete
  16. This is really an awesome post, thanks for it. Keep adding more information to this.mulesoft training in bangalore

    ReplyDelete
  17. I have read your blog its very attractive and impressive. I like it your blog. digital marketing training in bangalore

    ReplyDelete
  18. Your articles really impressed for me,because of all information so nice.servicenow training in bangalore

    ReplyDelete
  19. These provided information was really so nice,thanks for giving that post and the more skills to develop after refer that post.opennebula training in bangalore

    ReplyDelete
  20. I gathered a lot of information through this article.Every example is easy to undestandable and explaining the logic easily.openstack training in bangalore

    ReplyDelete
  21. Very useful and information content has been shared out here, Thanks for sharing it.salesforce developer training in bangalore

    ReplyDelete
  22. This is really an awesome post, thanks for it. Keep adding more information to this.vmware training in bangalore

    ReplyDelete
  23. Awesome,Thank you so much for sharing such an awesome blog.citrix training in bangalore

    ReplyDelete
  24. Thank you for sharing .The data that you provided in the blog is informative and effective.mulesoft training in bangalore

    ReplyDelete
  25. Really very happy to say, your post is very interesting to read. I never stop myself to say something about it. You’re doing a great job. Keep it up…

    Softgen Infotech is the Best Oracle Training institute located in BTM Layout, Bangalore providing quality training with Realtime Trainers and 100% Job Assistance.

    ReplyDelete
  26. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously in their life, he/she can earn his living by doing blogging.thank you for thizs article. pega online training , best pega online training ,
    top pega online training

    ReplyDelete
  27. Pretty good post. I have just stumbled upon your blog and enjoyed reading your blog posts very much. I am looking for new posts to get more precious info. Big thanks for the useful info.
    devops training in chennai | devops training in anna nagar | devops training in omr | devops training in porur | devops training in tambaram | devops training in velachery

    ReplyDelete

  28. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    mulesoft online training
    best mulesoft online training
    top mulesoft online training

    ReplyDelete

Thanks for visiting my blog.
However, if this helped you in any way, please take a moment to write a comment.

Thanks
Nirman