Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign c# guid value to javascript variable using razor viewmodel in asp.net mvc?

I have a view model with property of Guid type. I need to assign it to javascript object property and post this object to some action method.

When I write (in javascript):

var partyId = @Model.Id;  // "Id" is of Guid type

I get

var partyId = 6abbf77d-ba28-4d8a-87ff-2fa8f8a070c9;
// Uncaught SyntaxError: Unexpected identifier 

How can I handle this? I mean assign Id value to javascript variable.

like image 356
Aleksei Chepovoi Avatar asked Sep 27 '13 21:09

Aleksei Chepovoi


People also ask

How do you assign in C programing?

To assign a value to a C and C++ variable, you use an assignment expression. Assignment expressions assign a value to the left operand. The left operand must be a modifiable lvalue. An lvalue is an expression representing a data object that can be examined and altered.

What is assigning in C?

An assignment operation assigns the value of the right-hand operand to the storage location named by the left-hand operand. Therefore, the left-hand operand of an assignment operation must be a modifiable l-value. After the assignment, an assignment expression has the value of the left operand but is not an l-value.

What does %= mean in C?

%= Modulus AND assignment operator. It takes modulus using two operands and assigns the result to the left operand. C %= A is equivalent to C = C % A.


1 Answers

Enclose @Model.Id within quotes.

like image 146
Adam Miller Avatar answered Nov 14 '22 22:11

Adam Miller