I have an Asp.Net mvc 3 project
I’m using razor, and need to generate guids in javascript
I was trying this:
<script type="text/javascript">
$(document).ready(function () {
function getNewGuid() {
return '@Guid.NewGuid()';
}
I’m using inside the click event for a button, but the second call to the function is returning the same value
What should I do for reevaluating the function with each call?
The
is evaluated server-side when the page is rendered, so you will always get the same value.
You need a Javascript Guid library from somewhere.
Try the accepted answer to this question.
While you could make an Ajax call to the server, it’s pretty pointless if all you’re after is a unique value that could be generated far more efficiently client-side.