To route the MIDI in Sonar you need to treat each of the synth's MIDI in ports as if it's a separate instrument.
Which means picking the relevant synth MIDI in port as a MIDI track's output port and then setting the track's outgoing MIDI channel to whichever channel the sound you want is on. To record MIDI or play the synth, set the MIDI track's input port to the Alesis controller. You'll need to watch out which tracks are armed for recording and what's happening with MIDi track echoing to avoid MIDI being sent to the wrong place in the same way those of use using several hardware synths do.
As an example -
I have a DSI Mopho, Waldorf microQ and a Waldorf Pulse 2 all using 5-pin MIDI cables which I control off the same USB keyboard controller. The MIDI cables are connected to the computer by a couple of MIDI-USB interfaces each with several ports.
To do this I set the Mopho to channel 1, the Q to channels 2-5 and the Pulse to 6. It doesn't matter what channel the controller's set to.
I then create MIDI tracks as follows-
1. Mopho
2 Q
3 Q
4 Q
5 Q
6 Pulse
Each track output points at the MIDI interface port the relevant synth's MIDI cables are attached to. The input of each track points to the controller.
To play/record I select (highlight) the relevant MIDI track and turn on the track echo button. MIDI will then be routed by Sonar from the controller to the synth via the MIDI track. To play a different instrument or Q voice I simply switch track echo off on the track I was using and activate it on the track I now want to send MIDI through.
The main thing is not to try to record more than one of those MIDI tracks at a time, and to make sure only one at a time has input echo enabled (unless I want two synths to play the same notes of course).
If I wanted to I could even set the Pulse, Mopho and one Q voice to all use channel 1 and the routing would still work out OK. Which is very useful as I have an MD-20mini and a couple of other more oddball things that are fixed on MIDI channel 1 and can't be changed.
Edited to add - if, having recorded the MIDI from the controller I then want to add in CCs generated by the controls on each synth all I have to do is switch the MIDI track input over to the port attached to the synth's MIDI output and overdub the knob turning.