user1929393
user1929393

Reputation: 4277

Jquery get text value

When I use the following, I get this. Why does it not just return the exact value and not show the rest. I just want it to show "CVC" and "ACLYAU", instead of "{ Value = ACLYAU }" and "{ Value = ACLYAU }". When I try to pass this to my controller it breaks.

@Html.Hidden("princid", new { @Value = (@TempData["PrincId"]) })
@Html.Hidden("custid", new { @Value = (@TempData["CustId"]) })

  <script>
    var val = $("#princid").val();
    var val2 = $("#custid").val();

    alert(val);
    alert(val2);
  </script>

result

===>     "{ Value = CVC }"
===>     "{ Value = ACLYAU }"

desired output

   "CVC"
   "ACLYAU"

Upvotes: 1

Views: 66

Answers (1)

ianaya89
ianaya89

Reputation: 4243

Try replacing this:

@Html.Hidden("princid", new { @Value = (@TempData["PrincId"]) })
@Html.Hidden("custid", new { @Value = (@TempData["CustId"]) })

by this:

@Html.Hidden("princid", (object)@TempData["PrincId"])
@Html.Hidden("custid", (object)@TempData["CustId"])

Upvotes: 1

Related Questions