0

I have a form in an MVC view which, when submitted, passes back various values. But one of the values can be "70+" The problem is the plus sign is being passed back to the controller as a blank space i.e. "70 "

This is the input element as it appears on the view:

<input type="hidden" value="70+" name="TestInput">

It is produced using knockout.js from the following line:

<input type="hidden" data-bind="value:name" name="TestInput" />

When page first loads the plus sign is included in the model, but when the form is submitted the plus sign is no longer part of the model.

Note: The value of input is variable so it might not include a plus sign at all, but if it does I need it to be passed through correctly.

How can I make sure the plus sign is passed back to the controller?

May01
  • 15
  • 1
  • 6

1 Answers1

0

Just as @Steve mentioned in the comments the symbol needed to be encoded.

So I added a new property (encodedName) in the koViewModel using encodeURIComponent:

self.name = ko.observable(data.name);
self.encodedName = ko.observable(encodeURIComponent(data.name));

And then just used that in the form input instead of name:

<input type="hidden" data-bind="value:encodedName" name="TestInput" />
May01
  • 15
  • 1
  • 6