I am currently working with a model in my view that includes a property named 'list of numbers'
public myModel{
public string listOfNumber {get; set;}
Within my controller, I assign a string value to this property
public myController{
public ActionREsult myMethod(){
....
myModelObj.listOfNumber = myModelObj.listOfNumber +"["+aNumber+"]";
return PartialView("test/_myPartialView", myModelObj);
In my view, I have the following input element
<input type="hidden" <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee988f829b8bd3aea69a8382c0bc8f9">[email protected]</a>(Json.Encode(Model.listOfNumber)) id="listNumb"/>
When I use console.log()
to check the value of $("#listNumb").val()
, I see the following result
"[1][4][3][23]"
I am puzzled by the presence of the quotation marks. Upon further investigation, I discovered that when I pass the value back to the controller using model binding, it becomes \"[1][4][3][23]\"
. It appears that the quotation marks have been added to the string.
EDIT
Following a suggestion from one of the answers, here is what is displayed in the view source. Interestingly, whether I include quotation marks around
@Html.Raw(Json.Encode(Model.listOfNumber))
or not, the source output remains the same. ""[1][4][3][23]""
. It seems I missed the double quotes because I did not anticipate them :)