简体   繁体   中英

Partial escaping of characters between MVC and javascript

Background

Keeping the double backslash between server side and client side.

View Model

MyViewModel.Users { get "'domain\\user1', 'domain\\user2'"; }

Markup

On the page I output using:

var userArray = [ @Html.Raw(Model.Users) ];

Problem

viewing source shows:

var userArray = [ 'domain\user1', 'domain\user2' ];

This is causing errors. I want to keep the single quotes but double escape the backslash.

TIA....

Double escaping a backslash would be "\\\\\\\\" in C#.

This gives you an internal string that has two backslashes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM