I am trying to solve copy pasting a column with values from excel into a textarea in my web app.
The user will simply select row values in a column, e.g. the excel table looks like (the user will not select the header)
-----
|Code |
-----
| 1 |
-----
| 2 |
-----
| 3 |
-----
| 4 |
-----
| 5 |
-----
When I paste this into a text area, it pastes in with the spaces, e.g.
--------------------------------------------
|1 |
|2 |
|3 |
|4 |
|5 |
| |
--------------------------------------------
But when I post this text area to the controller, receiving it like so:
public ActionResult Search(string searchTerms)
{
//`searchTerms` = "12345"
...omitted for brevity...
}
This is a problem, as the codes represent separate object.
What would be the easiest way I could modify this so I can receive some sort of separator? Keeping in mind the user will just want to hit ctrl+v and have the entire list entered. Simple modifications to the excel spreadsheet to have the list separated on copy or alternative excel type solution would also be acceptable.
You could insert the separators when the text is pasted into the textarea. With something like the following
$("textarea").change(function() {
$(this).val($(this).val().split('\n').join(','));
});
Example: http://jsfiddle.net/ADwYg/
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