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.
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.
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.
%= 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.
Enclose @Model.Id within quotes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With